Jythonc : How to use?
I am new to jython. Here is my failed attempt to use javac to complie my python script into class file.
rohit@rohit-laptop:~/backyard$ echo "print 'hi'" > test.py
rohit@rohit-laptop:~/backyard$ jython test.py
hi
rohit@rohit-laptop:~/backyard$ jythonc test.py
Warning: jythonc is unmaintained and will not be included in Jython-2.3. See http://jython.org/Project/jythonc.html for alternatives to jythonc. Add '-i' to your invocation of jythonc to turn off this warning
processing test
Required packages:
Creating adapters:
Creating .java files:
test module
Compiling .java to .class...
Compiling with args: ['/usr/bin/javac', '-classpath', '/usr/share/java/jython.jar:/usr/share/java/servlet-api-2.4.jar:/usr/share/java/libreadline-java.jar:./jpywork::/usr/share/jython/Tools/jythonc:/usr/share/jython/Lib:/usr/lib/site-python:__classpath__', './jpywork/test.java']
0
rohit@rohit-laptop:~/backyard$
rohit@rohit-laptop:~/backyard$ cd jpywork/
rohit@rohit-laptop:~/backyard/jpywork$ ls
test.class test.java test$_PyInner.class
rohit@rohit-laptop:~/backyard/jpywork$ java test
Exception in thread "main" java.lang.NoClassDefFoundError: org/python/core/PyObject
Caused by: java.lang.ClassNotFoundException: org.python.core.PyObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClass开发者_如何学PythonLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: test. Program will exit.
rohit@rohit-laptop:~/backyard/jpywork$
Please suggest the correct way.
Jython will automatically compile it into .class file on first execution, however in case you want to compile it, you can use standard library, find py_compile.py or compileall.py on Jython lib folder.
$ java test # is not the exact command to execute the class file
this class file requires jython.jar
file to execute you have to give the jython.jar
path at the run time.
#java -cp /home/litindia/jython-2.0.1/jython.jar:. test
-cp
is compulsory /home/litindia/jython-2.0.1/jython.jar
is my path where is jython.jar
is present in my system, your path may be different. so please give the appropriate path.
And after the path :.
is compulsory. Then file name is required.
精彩评论