java - 使用 Eclipse 导入 py4j

标签 java python eclipse py4j

我已经阅读了 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 JAR。最简单的路线可能是:

  1. 在 Eclipse 项目中创建一个 lib 文件夹(如果尚不存在)。
  2. 将 p4yj 安装中的 py4j0.x.jar 复制到该 lib 文件夹中。
  3. 在 Eclipse Package Explorer(或 Project Explorer)中右键单击 JAR,选择构建路径> 添加到构建路径

此时,您可以查看 Eclipse 的 Problems 或 Markers View ,发现编译问题已经消失。当您再次运行该程序时,它应该会出现“未解析的编译...”错误。

关于java - 使用 Eclipse 导入 py4j,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37596091/

相关文章:

python - 设置matplotlib中y轴系数的颜色

java - Eclipse 是否有 "vim: set ft=cpp:"或 "-*- c++ -*-"的等价物?

java - JRebel 不是从 Liberty Server、Mac、Eclipse Luna、Java 8 运行时开始的

java - 为多目录项目制作文件

java - 如何在没有 Applets 的情况下在浏览器中显示 JFrame 应用程序

python - Python 如何使用 Gunicorn 和 Kubernetes 进行扩展?

python - 属性错误: 'Action' object has no attribute 'text1'

java - 在android上编程,错误为 "super(context);"

java - Eclipse 和其他用于调试并发代码的 Java IDE

java - HTTP SOAP 负载编码