Transilvania JUG



Using Jython from Maven

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) {

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.


One Response to Using Jython from Maven

  1. Daiane says:

    In Chapter 23 ( Miscellaneous ), sectoin 23.3 is Python and Java Programming with Jython . The sectoin is only 4 pages long (pp. 1002-1006). It illustrates a simple Hello, world program using Jython and Swing. Clearly, the purpose of the sectoin is simply to let the reader know that Jython exists; it is not enough to teach you everything you need to know to use Jython.

Leave a Reply

Your email address will not be published. Required fields are marked *