我是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 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$
请建议正确的方法。
答案 0 :(得分:0)
Jython会在第一次执行时自动将其编译成.class文件,但是如果你想编译它,可以使用标准库,在Jython lib文件夹中找到py_compile.py或compileall.py。
答案 1 :(得分:0)
$ 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
出现在我的系统中,您的路径可能会有所不同。所以请给出适当的路径。
路径:.
是强制性的。然后需要文件名。