从 Eclipse 插件使用 Jython

发布于 2024-08-12 01:20:24 字数 806 浏览 1 评论 0原文

当从 Eclipse 插件运行时,我很难让 jython 正常工作。我有一个简单的对象工厂,它加载符合 Java 接口的 python 模块。所有这些在独立模式下都可以正常工作。但是,当我将其打包为 eclipse 插件时,我会根据一些变量得到不同的错误:

假设我的 java 包是 com.foo。

1)如果我在不修改任何路径的情况下运行,我得到:“没有名为 foo 的模块”

2)如果我使用以下命令将我的 java jar 添加到 sys.path 中:

PythonInterpreter interp = new PythonInterpreter(null, new PySystemState());
PySystemState sys = Py.getSystemState();
sys.path.append(new PyString("myjar..."));

我得到:

a)我的 python 模块的构造函数被调用(在constr 出现)
b) 我得到一个从调用 tojava 中返回的 PySingleton。名称字段是“错误”。

3)此时,我尝试使 Eclipse 中的类路径与 Standalone 中的类路径完全相同,因此我在运行时调用 python 解释器之前将 jar 添加到类路径中。

我收到我最喜欢的错误消息: SystemError:自动代理初始化应该只发生在代理类上

这一条让我发疯。我对在独立模式下的运行速度印象深刻。在 Eclipse 下运行应该有那么大的不同吗?我相信这应该只是类路径的问题,但到目前为止,似乎并非如此。

I am having a tough time getting jython to work properly when run from an Eclipse plugin. I have a simple object factory that loads a python module conforming to a Java Interface. All of this works fine in standalone mode. However, when I package this as an eclipse plugin, I get a different error based on a few variables:

Given that my java package is com.foo.

1) If I run without modifying any paths, I get: "No module named foo"

2) If I then add my java jars to the sys.path using:

PythonInterpreter interp = new PythonInterpreter(null, new PySystemState());
PySystemState sys = Py.getSystemState();
sys.path.append(new PyString("myjar..."));

I get:

a) My python module's constructor gets called (print in the constr shows up)
b) I get a PySingleton returned from the call to tojava. The name field is "Error".

3) At this point, I try to make the classpath exactly the same in Eclipse as Standalone, so I add my jars to the classpath at runtime just before the python interpreter is called.

I get my favorite error message: SystemError: Automatic proxy initialization should only occur on proxy classes

This one is driving me crazy. I was impressed with how fast I got this going in standalone mode. Should running under Eclipse be that much different? I believe it should only be a matter of the classpath, but so far, that doesn't seem to be it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗失的美好 2024-08-19 01:20:24

终于把这个搞清楚了这是我必须做的:

1)我使用 JSR223 ScriptEngine 而不是 PythonInterpreter:

engine.get(module_name); //获取模块的类对象
类上的 getConstructors[0].newInstance(null) 来获取对象
//将其投射到您的界面!

2) 确保您的 Eclipse 插件没有打包为 jar (在 3.5 中设置 Eclipse-BundleShape: dir)
3) 将 jython.jar 和您想要将模块定位到的任何路径添加到清单中的运行时类路径。

希望这对某人有帮助。

Finally figure this one out. Here is what I had to do:

1) I used the JSR223 ScriptEngine instead of PythonInterpreter:

engine.get(module_name); //gets the class object of the module
getConstructors[0].newInstance(null) on the class to get an object
//cast it to your interface!

2) Make sure your Eclipse plugin isn't packaged as a jar (in 3.5 set Eclipse-BundleShape: dir)
3) Add jython.jar and any paths where you want to locate modules to your Runtime Classpath in the Manifest.

Hope this helps someone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文