在python模块中导入java类
我在 Java 中创建了一个包,并在其中创建了一个 publis 类。
package GX1164;
public class Test
{
public int add(int a)
{
return (a+a);
}
}
现在我必须在 python 模块中导入这个包和类来调用函数“add”。 但不知怎的,我无法导入测试类。我不断收到错误“未定义的模块测试”
I have created one package in Java and one publis class inside it.
package GX1164;
public class Test
{
public int add(int a)
{
return (a+a);
}
}
Now I have to import this package and class in python module to call the function "add".
But somehow I am not able to import the class Test. I keep getting the error "Undefined module Test"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将您的 java 类构建到 .jar 文件中,然后执行以下操作
将 jar 附加到 sys.path 与设置类路径相同。
Build your java class into a .jar file then do the following
Appending the jar to sys.path is the same as setting a class path.
好吧,您的模块名为
GX1164
,类名为Test
:您还需要确保以某种方式设置
CLASSPATH
这将允许 Jython 找到 Test.class。Well, your module is called
GX1164
and the class is calledTest
:You also need to make sure that the
CLASSPATH
is set up in a manner that will allow Jython to findTest.class
.