'Jython How to Use Standalone JAR?

I am trying to use the Jython PythonInterpreter class, but am struggling a bit.

Due to physical limitations, my scenario lacks any sort of project structure. I simply have a Jython JAR file and a Java file.

I am currently compiling my Java code like so:

javac -cp "jython-standalone-2.7.0.jar" test.java

This command does not fail.

When I try to run the compiled Java, I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/python/util/PythonInterpreter
        at test.main(test.java:9)
Caused by: java.lang.ClassNotFoundException: org.python.util.PythonInterpreter
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 1 more

The code looks like so:

import org.python.util.PythonInterpreter;

class test {
    public static void main(String[] args) {
        PythonInterpreter interpreter = new PythonInterpreter();
    }
}

The code is very simple. Should I be importing the Jython classes a different way? Does my method here have any chance of working?

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source