From: Danny Y. <dy...@hk...> - 2001-11-19 23:29:10
|
I've been experimenting with jythonc, and one of my experiments was to play around with Java interfaces. In the course of my experiments, I've been running my head into a strange AttributeError. Since I'm not too familiar with Jython, I'll report the steps I've done in some detail; forgive me if much of this is extraneous! The error message is at the very bottom, and this message traces what I've done to get the message. I have the following Java interface: ### [dyoo@tesuque bar]$ cat EvalInterface.java public interface EvalInterface { public int eval(int x); } ### I've written a few Jython files that extend this interface: ### [dyoo@tesuque bar]$ cat Doubler.py import EvalInterface class Doubler(EvalInterface): def __init__(self): pass def eval(self, x): return x + x [dyoo@tesuque bar]$ cat Squarer.py import EvalInterface class Squarer(EvalInterface): def __init__(self): pass def eval(self, x): return x * x ### and I've compiled my Jython files into a single .jar file: ### processing Doubler processing Squarer Required packages: Creating adapters: Creating .java files: Squarer module Squarer extends java.lang.Object implements EvalInterface Doubler module Doubler extends java.lang.Object implements EvalInterface Compiling .java to .class... Compiling with args: ['/usr/local/bin/jikes', '-classpath', '/home/dyoo/local/jython-2.1a3/jython.jar:.:/opt/jdk1.3.0_02/jre/lib/rt.jar:/home/dyoo/local/jython-2.1a3/jython.jar:./test.jar:./jpywork::/home/dyoo/local/jython-2.1a3/Tools/jythonc:/home/dyoo/bar/.:/home/dyoo/local/jython-2.1a3/Lib', './jpywork/Squarer.java', './jpywork/Doubler.java'] 0 Building archive: test.jar Tracking java dependencies: ### Once this was done, I adjusted my CLASSPATH to include this jar file: ### export CLASSPATH=.:/opt/jdk1.3.0_02/jre/lib/rt.jar:\ /home/dyoo/local/jython-2.1a3/jython.jar:./test.jar ### and wrote a small java test.java to see if everything worked. ### [dyoo@tesuque bar]$ cat foo.java public class foo { static public void main(String[] args) { EvalInterface f1 = new Square(); System.out.println(f1.eval(42)); EvalInterface f2 = new Double(); System.out.println(f2.eval(42)); } } ### And this worked! ### [dyoo@tesuque bar]$ java Test 1764 84 ### However, I ran into problems when I tried playing with my classes in Jython. To force Jython to use my jythonc-compiled classes, I made a new directory called "scratch". Here's the log: ### [dyoo@tesuque bar]$ mkdir scratch [dyoo@tesuque bar]$ cp test.jar scratch/ [dyoo@tesuque bar]$ cd scratch [dyoo@tesuque scratch]$ cp ../EvalInterface.class . [dyoo@tesuque scratch]$ echo $CLASSPATH .:/opt/jdk1.3.0_02/jre/lib/rt.jar:/home/dyoo/local/jython-2.1a3/jython.jar:./test.jar [dyoo@tesuque scratch]$ jython Jython 2.1a3 on java1.3.0_02 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> import Doubler >>> Doubler <jclass Doubler at 5868800> >>> d = Doubler() >>> d.eval(42) Traceback (innermost last): File "<console>", line 1, in ? AttributeError: abstract method "eval" not implemented ### I'm just scratching my head on this one. Are Jythonc-compiled classes reusable from Jython itself? Any help on this would be greatly appreciated. Thank you! |