Following Using Jython Within Java Applications, I could integrate Java and Jython (Java methods can call python scripts). The python code is located inside py
directory. The Jython uses sys.path.append("py")
command to find the Jython scripts.
Then, I tried to integrate all the files into a single jar file.
For the pre step, I could generate one jar file, and copied the py directory along side with the jar file, and it works fine. I used IntelliJ IDEA for generating a jar file.
│ └── py
│ ├── Context$py.class
│ ├── Context.py
│ ├── Host$py.class
│ └── Host.py
├── aggregationPython.jar <-- Generated jar file
For the next step, I tried to copy the py directory inside the jar file, I also used IntelliJ for that.
I checked that the jar file has the py directory in the jar file. You see that the py directory is located at the root of jar file.
However, when I executed the jar file, I got an error saying the jython module is missing.
> java -jar aggregationPython.jar
Exception in thread "main" ImportError: No module named Host
What might be wrong? I assumed the py directory can be stored in a jar file to be found just like it is found outside the jar file. What's wrong with this assumption?