【发布时间】:2016-06-02 15:26:58
【问题描述】:
我已经阅读了 py4j.org 介绍的第一部分,然后我跳到了 Eclipse 部分。我安装了在这里找到的 Eclipse 插件:http://eclipse.py4j.org/,然后重新启动了 Eclipse。
我在预先存在的 Java 项目中有一个名为 DateRange 的类,因此我按照说明创建了一个名为 DateRangeEntryPoint 的新类。这由以下代码组成。
package statresearch.programs.DaypartParser;
import statresearch.programs.util.DateRange;
import py4j.GatewayServer;
public class DateRangeEntryPoint {
private DateRange dateRange;
public DateRangeEntryPoint(String startDate, String endDate, boolean includeStart, boolean includeEnd) {
dateRange = new DateRange(startDate, endDate, includeStart, includeEnd);
}
public DateRange getDateRange() {
return dateRange;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
GatewayServer gatewayServer = new GatewayServer(new DateRangeEntryPoint());
gatewayServer.start();
System.out.println("Gateway Server Started");
}
}
但是,当我尝试在 eclipse 中运行它时,我收到以下错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
GatewayServer cannot be resolved to a type
GatewayServer cannot be resolved to a type
The constructor DateRangeEntryPoint() is undefined at statresearch.programs.DaypartParser.DateRangeEntryPoint.main(DateRangeEntryPoint.java:22)
我坚持的是如何在 Eclipse 中导入 py4j,以便我可以在 Python 中使用已经在 Eclipse 项目中定义的对象。
【问题讨论】:
-
也许你需要 py4j 依赖于你的类路径 - mvnrepository.com/artifact/net.sf.py4j/py4j/0.8.1
-
eclipse.py4j.org 是 OSGi 包/Eclipse 插件的存储库。只有在您自己开发插件时使用它们才有意义。如果它是一个常规的 Java 项目,Py4J eclipse 插件将无济于事。
-
谢谢你的问题,我知道我必须在新人的文档中更清楚地说明这一点。
-
别担心,我绝对是 Java 初学者。下面的方法有效,我正在关闭并运行我的 python 包中的 Java 对象。感谢这个很棒的包!