gpt4 book ai didi

java - 导出的 eclipse-plugin 无法执行 python 脚本

转载 作者:行者123 更新时间:2023-12-02 02:43:14 24 4
gpt4 key购买 nike

我希望有人可以帮助我了解如何解决我的问题:

导出的 eclipse-plugin 的 python.exe 和调用的 python 脚本 (test.py) 的路径错误。因此,当插件正常调用脚本时,它会抛出错误。

有没有办法将 python 和相应的 python 文件与 .jar 一起编译,或者是否有其他方法可以正确执行此操作?

我创建了一个 eclipse 插件,它通过 ProcessBuilder 类调用 python 脚本。 python 脚本导入 lxml 并对两个 xml 文件执行一些合并步骤。当我将插件作为“Eclipse 应用程序”启动时,脚本将被执行并且一切正常。当我将插件导出为 .jar 文件时,我无法调用 python 脚本,因为它在 .jar 文件中附加了 python.exe 和 test.py 的路径(例如“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);

绝对路径的意思是这样的:“C:/Users/user/path/to/project/venv/Scripts/python.exe”(它是通过“virtualenv venv”创建的virtualenv)

如上所述,出现以下错误:1) 当插件调用 test.py 时,找不到“C:/Users/user/eclipse/plugins/plugin.jar_100/src/utils/test.py”2) java.io.IOExeption: 无法运行程序 "C:\absolute\path\eclipse\plugins\plugin_133.jar\venv\Scripts\python.exe": CreateProcess error=2, 系统找不到指定的文件。

最佳答案

导出的插件通常将所有内容打包到一个 jar 中。 jar 中的对象不是文件,您无法使用 ProcessBuilder 等需要文件的东西来访问它们。

您可以包含

Eclipse-BundleShape: dir

在插件的 MANIFEST.MF 中将插件构建为目录而不是 jar。内容将是普通文件。

如果插件包含在“功能”中,则“安装后解压插件存档”选项将覆盖 manifest.mf 设置。

关于java - 导出的 eclipse-plugin 无法执行 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57164671/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com