PyDev:Jython 模块和同一项目中的 Java 类
我来自 Java 世界,对 Jython 完全陌生。
是否可以在 Eclipse 中创建一个项目,并在同一项目上同时包含 Jython 和 Java 类?我尝试这样做 - 编写一个简单的 Java 类并在 Jython 模块中使用它 - 并且在编码过程中一切都很顺利。但是当我尝试运行该项目时,我得到:
Traceback (most recent call last):
File "/home/bahman/Work/Jython/TestJython/src/com/bahmanm/Main.py", line 1, in <module>
from com.bahmanm import Greeter
ImportError: cannot import name Greeter
Java 类是: 包 com.bahmanm;
public class Greeter {
private String msg;
public Greeter() {
msg = "Hello, ";
}
public void greet(String name) {
System.out.println(msg + name);
}
}
Jython 模块非常简单:
from com.bahmanm import Greeter
g = Greeter()
g.greet("Bahman")
我很感激任何想法/提示。
I come from a Java world and am totally new to Jython.
Is it possible to create a project in Eclipse with both Jython and Java classes on the same project? I tried to do so -writing a simple Java class and using it in Jython module- and everything went fine during coding. But when I try to run the project I get:
Traceback (most recent call last):
File "/home/bahman/Work/Jython/TestJython/src/com/bahmanm/Main.py", line 1, in <module>
from com.bahmanm import Greeter
ImportError: cannot import name Greeter
The Java class is:
package com.bahmanm;
public class Greeter {
private String msg;
public Greeter() {
msg = "Hello, ";
}
public void greet(String name) {
System.out.println(msg + name);
}
}
And the Jython module is quite simple:
from com.bahmanm import Greeter
g = Greeter()
g.greet("Bahman")
I'd appreciate any ideas/hints.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将您的 java 代码添加到 jython-project 的 Pythonpath
项目
属性 -> PyDev PYTHONPATH ->;外部库
Add your java-code to the Pythonpath of your jython-project
Project
Properties -> PyDev PYTHONPATH -> External Libraries
尝试添加
在顶部
try adding
at the top
当你运行它时,你将 jar 添加到 jython 的构建路径:
jython -Dpython.path=[jarname] [pyfilename]
when u run it, u add jars to jython's build path with:
jython -Dpython.path=[jarname] [pyfilename]