5

I'm using jython 2.7 with java, with the objective of creating a python wrapper around my jar file (let's call it myJar.jar)

Here's my python file:

import sys
sys.path.append('/pathTo/myJar.jar')
from java.lang import Math #this works
from java.io import File # this works`

from com.myPackage.classes import myClass

print('trying to import myClass')

I run the following command to execute this code:

java -jar ~/pathTo/jython.jar jyTest.py

I get an importError stating: ImportError: No module named myPackage

aside from using sys.path.append(), I've also tried:

java -jar ~/pathTo/jython.jar -Dpython.path=/pathTo/myJar.jar jyTest.py

and

java -cp ~/pathTo/jython.jar:~/pathTo/myJar.jar jyTest.py

and

java -classpath ~/pathTo/myJar.jar -jar ~/pathTo/jython.jar jyTest.py

I also tried using java -cp by exporting myJar.jar to $CLASSPATH.

None of the above approaches worked.

Please note that if I do not add the line from com.myPackage.classes import myClass, I can see the print statement being executed, therefore, my jython.jar is working as expected.

I installed jython 2.7 Standalone package, as per the instructions given on: https://wiki.python.org/jython/InstallationInstructions

...therefore I only have jython.jar

How should I make myJar.jar visible to my python file ? Thanks

Saransh Kejriwal
  • 2,467
  • 5
  • 15
  • 39

0 Answers0