By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

Can't get compiled jython to work...

P: n/a
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)
Dec 14 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

Dec 14 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.