0

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.

3
  • 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. Commented Dec 6, 2011 at 20:00
  • My code looks like Process p = r.exec("python ./myPath/myScript.py"); I am not sure, that means as a file? Commented Dec 6, 2011 at 20:03
  • it's a system command, so yes, you're looking for a file. Please check out edit to my answer below. Commented Dec 6, 2011 at 20:06

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
I'll investigate Jython now, I thought I was so close, it all worked until I put my Java code in a jar file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.