jython – Grey Panthers Savannah https://grey-panther.net Just another WordPress site Thu, 13 Oct 2011 15:16:00 +0000 en-US hourly 1 https://wordpress.org/?v=6.9 206299117 Using Jython from Maven https://grey-panther.net/2011/10/using-jython-from-maven.html https://grey-panther.net/2011/10/using-jython-from-maven.html#respond Thu, 13 Oct 2011 15:16:00 +0000 https://grey-panther.net/?p=40 This blogpost was originally posted to the Transylvania JUG blog.

On the surface it looks simple: just add the dependency and you can run the example code.

However what the jython artifact doesn’t get you are the standard python libraries like re. This means that as soon as you try to do something like the code below, it will error out:

PythonInterpreter interp = new PythonInterpreter();
try {
  interp.exec("import re");
} 
catch (PyException ex) {
  ex.printStackTrace();
}

The solution? Use the jython-standalone artifact which includes the standard libraries. An other advantage is that it has the latest release (2.5.2) while jython lags two minor revisions behind (2.5.0) in Maven Central. A possible downside is the larger size of the jar.

<dependency>
    <groupId>org.python</groupId>
    <artifactId>jython-standalone</artifactId>
    <version>2.5.2</version>
</dependency>
]]>
https://grey-panther.net/2011/10/using-jython-from-maven.html/feed 0 40