2011-05-31 22 views
0

我是jython的新手。這裏是我嘗試使用javac編譯我的python腳本到類文件失敗的嘗試。Jythonc:如何使用?

[email protected]:~/backyard$ echo "print 'hi'" > test.py 
    [email protected]:~/backyard$ jython test.py 
    hi 
    [email protected]:~/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 
    [email protected]:~/backyard$ 
    [email protected]:~/backyard$ cd jpywork/ 
    [email protected]:~/backyard/jpywork$ ls 
    test.class test.java test$_PyInner.class 
    [email protected]:~/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. 
    [email protected]:~/backyard/jpywork$ 

請建議正確的方法。

+3

在閱讀jythonc網頁後,我會推薦放棄jythonc(它似乎是他們推薦的) – KevinDTimm 2011-05-31 07:39:04

+0

如果您有'jythonc',那麼您必須運行Jython 2.2。我們在2.5.1,而Jython在最近的幾個版本中有了很大的改進。 – 2011-05-31 08:47:39

+0

是的..我選擇放棄它。 – Nullpoet 2011-05-31 08:58:31

回答

0

Jython會在第一次執行時自動將它編譯成.class文件,但是如果您想編譯它,可以使用標準庫,在Jython lib文件夾中找到py_compile.py或compileall.py。

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出現在我的系統,您的路徑可能會有所不同。所以請給出適當的路徑。

並且路徑:.是強制性的。然後文件名是必需的。