简体   繁体   中英

Exported eclipse-plugin is not able to execute python script

I hope that someone can help me understand how to fix my problem:

The exported eclipse-plugin has wrong paths to python.exe and the called python script (test.py). Therefore when the plugin would normaly call the script, it throws errors.

Is there a way to compile python and the corresponding python file together with the .jar or is there another way to do this properly?

I've created an eclipse-plugin that calls a python script via ProcessBuilder-class. The python script imports lxml and does a few merging steps of two xml files. When I start the plugin as "Eclipse Application" the script is executed and everything is working. When I export the Plugin as .jar file, I can't call the python script, because it appends the path to python.exe and to test.py at the .jar file (eg "plugin.jar/test.py).

// Init the processBuilder
ProcessBuilder procBuilder = new ProcessBuilder(
absolute/path/to/venv/Scripts/python.exe", // Possible workaround: "python",
absolute/path/to/test.py, 
arg1, arg2);

absolute path means something like this: "C:/Users/user/path/to/project/venv/Scripts/python.exe" (its a virtualenv created via "virtualenv venv")

Like mentioned above the following error occurs: 1) "C:/Users/user/eclipse/plugins/plugin.jar_100/src/utils/test.py" is not found when the plugin should call the test.py 2) java.io.IOExeption: cannot run program "C:\\absolute\\path\\eclipse\\plugins\\plugin_133.jar\\venv\\Scripts\\python.exe": CreateProcess error=2, The system cannot find the file specified.

Exported plug-ins normally have all the contents packed in to a jar. Objects in a jar are not files and you can't access them using things like ProcessBuilder that expect files.

You can include

Eclipse-BundleShape: dir

in the MANIFEST.MF for the plug-in to build the plug-in as a directory rather than a jar. The contents will then be normal files.

If the plug-in is included in a 'feature' then the 'unpack plug-in archive after installation' option overrides the manifest.mf setting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM