Hmm, it didn't work. Here's what I tried.

I have a class in foo/
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.


On Thu, Feb 26, 2009 at 12:35 PM, Leo Soto M. <> wrote:
On Thu, Feb 26, 2009 at 12:51 PM, Jacob Fenwick <> 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.