Can't get compiled jython to work...

Dave Kuhlman dkuhlman at rexx.com
Fri Dec 14 18:23:57 EST 2007


kramer31 wrote:

> Hi.  First, I'm not sure if this is the correct group, but becuase I
> couldn't find a jython newsgroup, I'll post here.
> 
> I'm new to jython and am just trying to get it to work.  Interpreted
> jython works just fine, but I still can't get my compiled jython to
> work.
> 
> When I do this:
> 
> jythonc fac.py (where fac.py is a jython program), it creates a
> jpywork directory with three files fac.java, fac.class, and fac
> $_PyInner.class
> 
> But if I cd to that directory and do this:
> 
> java -classpath $JYTHON_HOME/jython.jar fac
> 
> I get this error:
> 
> Exception in thread "main" java.lang.NoClassDefFoundError: fac
> 
> 
> My fac.py looks like this:
> 
> def fac(x):
>         if x <= 1: return 1
>         return long(x) * fac(x-1)
> 
> if __name__ == "__main__":
>         print 1 + 2
>         print "Hello" + "Goodbye"
>         print "fac(3): "
>         print fac(3)
>         print "fac(100): "
>         print fac(100)

Build your jar with the following:

    $ jythonc -j fac.jar -a fac.py

Then run it with the following:

    $ java -jar fac.jar
    3
    HelloGoodbye
    fac(3):
    6
    fac(100):
    933262154439441526816992388562667004 [...]

Some more hints and suggestions:

1. If you want to generate a java class usable from java, then your module
must obey a few rules: (1) It must be contain one class whose name is the
same as the module name.  (2) That class must inherit from some Java class.

2. If you have not already found it, see this page for more information:

       http://www.jython.org/docs/jythonc.html

3. jythonc is deprecated, I believe.  It is unclear what will happen to it
in the next version of jython.  So, maybe you do not want to get too
dependent on it.

Hope this helps.

Dave


-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman




More information about the Python-list mailing list