使用 pydev 从 jython 生成 .class 文件
我对 jython 的第一次尝试是我在 eclipse 中使用 pydev 编写的 java/jython 项目。
我创建了一个java项目,然后通过RightClick项目>>将其设为pydev项目 pydev>> 设置为...你明白了。 然后我添加了两个源文件夹,一个用于java,一个用于jython,每个源文件夹都有一个包。 我将每个文件夹设置为项目的构建路径。 我想我让你知道这一切,所以希望你能告诉我我是否正确设置了项目。
但真正的问题是:如何将 jython 代码制作成类文件,以便 java 代码可以使用它? 首选方法是 eclipse/pydev 会自动为我执行此操作,但是我想不通。 jython 用户指南中提到的内容暗示这是可能的,但我在任何地方都找不到有关它的信息。
编辑:我确实找到了一些信息这里和这里,但事情进展得不太顺利。
我一直在密切关注第二个链接中的指南,但我不知道如何让 jythonc 为我的 python 类创建构造函数。
My first attempt at jython is a java/jython project I'm writing in eclipse with pydev.
I created a java project and then made it a pydev project by the RightClick project >> pydev >> set as... you get the idea. I then added two source folders, one for java and one for jython, and each source folder has a package. And I set each folder as a buildpath for the project. I guess I'm letting you know all this so hopefully you can tell me wether or not I set the project up correctly.
But the real question is: how do I get my jython code made into a class file so the java code can use it? The preferred method would be that eclipse/pydev would do this for me automatically, but I can't figure it out. Something mentioned in the jython users guide implies that it's possible but I can't find info on it anywhere.
EDIT: I did find some information here and here, but things are not going too smooth.
I've been following the guide in the second link pretty closely but I can't figure out how to get jythonc to make a constructor for my python class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Jythonc 不再存在,它已被分叉到另一个名为 Clamp 的项目,但话虽如此...
来源 - Jython Newsletter,2009 年 3 月
当我向它提供一个包含 Python 2.7 代码的文件夹时(知道它在 Jython 2.5 中会失败),它确实输出了一个 .class 文件,即使它不起作用。 用您的 Jython 脚本尝试一下。 如果有效,请告诉我们,因为我很快就会到达您所在的地方。
一旦您做到了这一点,将命令行语句转换为 PyDev 中可以根据需要调用的外部工具并不困难。
Jythonc doesn't exist anymore, it has been forked off to another project called Clamp, but with that said...
Source - Jython Newsletter, March 2009
When I fed it a folder with Python 2.7 code (knowing it would fail in Jython 2.5) it did output a .class file, even though it doesn't function. Try that with your Jython scripts. If it works, please let us know, because I'll be where you are soon enough.
Once you're that far, it isn't hard to convert your command line statement to an External Tool in PyDev that can be called as needed.
遵循“在不使用 jythonc 的情况下从 Java 访问 Jython”教程之后,可以在 Java 代码中使用 jython 模块。 唯一棘手的一点是 *.py 模块不会编译为 *.class 文件。 所以事实证明这是java内部的奇异脚本。 与 jython'ed py 模块相比,性能当然可能会下降,但正如我从 jython 社区页面得到的那样,它们不会支持 jythonc (事实上已经在 jython2.5.1 中放弃了它)。
因此,如果您决定采用非 jythonc 方法,那么上面的教程是完美的。 我必须稍微修改 JythonFactory.java 代码:
Following the "Accessing Jython from Java Without Using jythonc" tutorial it became possible to use the jython modules inside java code. The only tricky point is that the *.py modules do not get compiled to *.class files. So it turns out to be exotic scripting inside java. The performance may of course degrade vs jythonc'ed py modules, but as I got from the jython community pages they are not going to support jythonc (and in fact have already dropped it in jython2.5.1).
So if you decide to follow non-jythonc approach, the above tutorial is perfect. I had to modify the JythonFactory.java code a bit: