Question

I just call a script inside the Java code:

try {
    Runtime.getRuntime().exec("PlotFiles.py" + FinalCallStringCMD + " -w 1");
 } catch (IOException ex) {// catch ex   }

I have then two question:

1) How can I indicate the script in the code as part of the package and not as hardcoded path (ex. /users/pinc/Plot.py)

2) How can I embed the Python script in the JAR file, so I can always call it?

Was it helpful?

Solution

I would think you could do something similar to the solution in this question, which should solve both issues. I.E., put the Python file in some location below the src directory, and then load it using a relative path with the src directory as the "root", using the ResourcesLoader.

I think you could call the getPath() method on the returned URL to achieve your needs, but I haven't tried this.

OTHER TIPS

Load the scripts as resources from your jar file and use jython via a javax.script.ScriptEngineManager to execute them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top