5

I have implemented a Java application that includes Jython to run Python scripts. When I run that application from the IDE (Eclipse or IDEA), then all works fine, the Python scripts are processed correctly.

However, when I package everything into a JAR file (to be released), including the jython.jar file, then I get the following error as soon as the Java application tries to run the first Python script:

ImportError: No module named os

So it seems that the Lib folder with all the standard Python modules is not found. I checked the jython.jar file that is included in the Java application's JAR file, and it does include the Lib folder correctly. In fact, that is the same jython.jar file that is also used when I run the application from the IDE, where it works.

I know one can specify the -Dpython.path paramter, but I don't know what to set here. How can I refer to the the Lib folder which is within the jython.jar file which is within the main application's JAR file?

Matthias
  • 9,817
  • 14
  • 66
  • 125

1 Answers1

0

I encounter the same problem, here is my solution: In your python script, add Lib path to sys path. Following is the code:

import sys
libPath="C:\\jython2.7b1\\Lib"
sys.path.append(libPath)
forrest
  • 94
  • 5