I have a jar file that launches a python script. It works if my jar file is at the root of the working directory. If I move it out of the working directory, it cannot find the python script anymore. Why does my call to find the script file not look inside the jar? I use ./(the path). Why does it automatically look in the working directory? I thought it would be self-contained.
Asked
Active
Viewed 826 times
0
-
Are you looking for the python script as a `file`? or as a `resource`? You might want to share more information about your problem because right now all anyone can do is guess. My guess is that you're trying to read the Python script as a file, and files don't exist inside of jars. – Hovercraft Full Of Eels Dec 06 '11 at 20:00
-
My code looks like Process p = r.exec("python ./myPath/myScript.py"); I am not sure, that means as a file? – smuggledPancakes Dec 06 '11 at 20:03
-
it's a system command, so yes, you're looking for a file. Please check out edit to my answer below. – Hovercraft Full Of Eels Dec 06 '11 at 20:06
1 Answers
1
Reposting my guess as an answer:
Are you looking for the python script as a file? or as a resource? You might want to share more information about your problem because right now all anyone can do is guess. My guess is that you're trying to read the Python script as a file, and files don't exist inside of jars. To solve this, either read the Python script as a file outside of Java, or look for it as a resource inside of the jar. If the latter, I'm not sure if you can run the script or not.
For more, please see this link: stackoverflow: can-i-make-a-jar-execute-a-python-script
Another clever option: stackoverflow: how-do-you-invoke-a-python-script-inside-a-jar-file-using-python

Community
- 1
- 1

Hovercraft Full Of Eels
- 283,665
- 25
- 256
- 373
-
What about if I converted my python script to Jython and had that execute from the Main class? Right now my Main class is trying to execute a Python script. – smuggledPancakes Dec 06 '11 at 20:08
-
I'll investigate Jython now, I thought I was so close, it all worked until I put my Java code in a jar file. – smuggledPancakes Dec 06 '11 at 20:15