Java Jythonc:如何使用?
我是jython的新手。下面是我使用javac将python脚本编译到类文件中的失败尝试Java Jythonc:如何使用?,java,jython,Java,Jython,我是jython的新手。下面是我使用javac将python脚本编译到类文件中的失败尝试 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 unmai
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(URLClassLoader.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$
请建议正确的方法。Jython将在第一次执行时自动将其编译到.class文件中,但是如果要编译它,可以使用标准库,在Jython lib文件夹中查找py_compile.py或compileall.py
$ java test # is not the exact command to execute the class file
这个类文件需要执行jython.jar
文件,您必须在运行时给出jython.jar
路径
#java -cp /home/litindia/jython-2.0.1/jython.jar:. test
-cp
是强制性的/home/litindia/jython-2.0.1/jython.jar
是我的路径,其中是jython.jar
存在于我的系统中,您的路径可能不同。因此,请给出适当的路径
路径
:.
之后是强制的。然后需要文件名。在阅读jythonc网页后,我建议您放弃jythonc(这似乎是他们的建议)。如果您有jythonc
,那么您必须运行Jython 2.2。我们的版本是2.5.1,Jython在过去的几个版本中有了很大的改进。是的。。我选择放弃它。