程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

使用 Eclipse 导入 py4j

发布于2021-12-17 09:48     阅读(1647)     评论(0)     点赞(18)     收藏(0)


我已经阅读了 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. lib在 Eclipse 项目中创建一个文件夹(如果它不存在)。
  2. py4j0.x.jarp4yj 安装中的复制到该lib文件夹中。
  3. 在 Eclipse Package Explorer(或 Project Explorer)中右键单击 JAR,选择Build Path > Add to Build Path

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



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.javaheidong.com/blog/article/360782/ac636dc2ff5350dc5caf/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

18 0
收藏该文
已收藏

评论内容:(最多支持255个字符)