euraad
euraad

Reputation: 2846

Add external JAR's to a Gluon project using Eclipse IDE?

I'm trying to include EasyModbusJava.jar and commons-lang3-3.8.1.jar in a JavaFX Gluon project using Eclipse. But when I compile, I get this:

/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;

How can I in a very easy and proper way, using Eclipse, to include JAR files into a Gluon project? I don't want to include the JAR files with a non-standard way, like editing an file and copy and paste. It can break my project. It's better to use the tools from the IDE instead.

picture

Upvotes: 0

Views: 443

Answers (1)

user7399085
user7399085

Reputation: 242

The only way that I know is to include the respective jars in the build.gradle

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

The jars show in eclipse under "Project and External dependencies" and their properties (e.g. path to javadoc) can not be edited. To achieve this you can add

apply plugin: 'eclipse'

and

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>')
        }
    }
}

to gradle.build

Upvotes: 1

Related Questions