【问题标题】:Add external JAR's to a Gluon project using Eclipse IDE?使用 Eclipse IDE 将外部 JAR 添加到 Gluon 项目?
【发布时间】:2019-03-14 17:23:13
【问题描述】:

我正在尝试在使用 Eclipse 的 JavaFX Gluon 项目中包含 EasyModbusJava.jarcommons-lang3-3.8.1.jar。但是当我编译时,我得到了这个:

/home/dell/Dokument/eclipse-workspace-2018-09/OKIDERAMPC/OKIDERAMPCApp/src/main/java/com/gluonapplication/thread/ModbusConnection.java:6: error: package org.apache.commons.lang3 does not exist
import org.apache.commons.lang3.ArrayUtils;

/home/dell/Dokument/eclipse-workspace-2018-09/OKIDERAMPC/OKIDERAMPCApp/src/main/java/com/gluonapplication/thread/ModbusConnection.java:8: error: package de.re.easymodbus.modbusclient does not exist
import de.re.easymodbus.modbusclient.ModbusClient;

如何使用 Eclipse 以一种非常简单且正确的方式将 JAR 文件包含到 Gluon 项目中?我不想以非标准方式包含 JAR 文件,例如编辑文件并复制和粘贴。它可以破坏我的项目。最好使用 IDE 中的工具。

picture

【问题讨论】:

    标签: java eclipse gluon-mobile gluon-desktop


    【解决方案1】:

    我知道的唯一方法是在 build.gradle 中包含相应的 jar

    dependencies {
        compile 'com.gluonhq:charm:5.0.1'
        compile files('<Path_to_jar>/EasyModbusJava.jar'
                        , '<Path_to_jar>/commons-lang3-3.8.1.jar'
        )
    }
    

    在“项目和外部依赖项”下的 Eclipse 中显示的 jars 及其属性(例如 javadoc 的路径)无法编辑。 为此,您可以添加

    apply plugin: 'eclipse'
    

    eclipse  {
        classpath {
           downloadJavadoc = true // to get the Gluon mobile (charm...) javadocs; 
           file {
                whenMerged { cp ->
                    // Add other javadoc and sources to classpath entry
                    def fileReferenceFactory = new org.gradle.plugins.ide.eclipse.model.internal.FileReferenceFactory()
    
                    def defvar1 = cp.entries.find{ defvar1 -> defvar1.path.endsWith('EasyModbusJava.jar') }
                    // add javadoc path
                    defvar1.javadocPath = fileReferenceFactory.fromPath('<Path_to_javadoc>')
                    // add source path
                    defvar1.sourcePath = fileReferenceFactory.fromPath('<Path_to_javasource>')
            }
        }
    }
    

    到 gradle.build

    【讨论】:

      猜你喜欢
      • 2012-01-22
      • 1970-01-01
      • 1970-01-01
      • 2013-09-23
      • 2021-10-17
      • 2012-03-14
      • 2012-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多