Can't get compiled jython to work...

K

kramer31

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)
 
K

kyosohma

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.


If you go to the main jython site at www.jython.com, you will notice a
link on the left under the "Community" header that is titled "Mailing
Lists".

I've never used Jython, so hopefully they can help you...or maybe one
of the Jython moguls here will lend you some advice.

Mike
 
D

Dave Kuhlman

kramer31 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top