From: Jacob F. <jac...@gm...> - 2009-02-27 03:09:08
|
Hmm, it didn't work. Here's what I tried. I have a class in foo/Test.java: package foo; class Test { public String print() { return "Printing\n"; } } I compile it, then create a jar: jar -cvf classes.jar foo Then I run these commands in jython: >>> import sys >>> sys.path.append('/Users/jacob/projects/djython/jython_test/classes.jar') >>> from foo import Test >>> t = Test() >>> t.print() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'foo.Test' object has no attribute 'print' >>> Hmmm. If I dir the t object I don't find a print function so I know it's not there. I feel like these steps I've followed should be working. If someone has a few minutes to look at it and tell me what I'm doing wrong I'd greatly appreciate it. Jacob On Thu, Feb 26, 2009 at 12:35 PM, Leo Soto M. <leo...@gm...> wrote: > On Thu, Feb 26, 2009 at 12:51 PM, Jacob Fenwick <jac...@gm...> > wrote: > > I'm looking for the simplest possible tutorial for Jython for importing a > > Java class. One that's not in the standard JDK. > > If it is on the CLASSPATH, it is the same as with classes bundled on > the JDK. If it's not, you can add the jar file to the python path: > > >>> sys.path.append('/path/to/file.jar') > > And again, just import is as normal. > > -- > Leo Soto M. > http://blog.leosoto.com > |