Steinliiippp
Steinliiippp

Reputation: 371

How to use external Jars in javafxports-Application

i write a javafx andoid application in netbeans with javafxports and gradle. I added the dependencies to gradel, but now i dont know how to add the jars to my project or to use it in my app-code. . .

Do you know how i can us it? I tried searching the www for hours ...

Ok i tried it but i dont get it ...

I did exactly what you said but netbeans still says: package io.netty.bootstrap does not exist

I created a folder unter src/android/ called libs and add my jar there ...

Here are my dependencies:

dependencies {
    compile fileTree(dir: 'src/android/libs', include: ['*.jar'])
    compile files('src/android/libs/netty-all-4.0.29.Final.jar')
}

FINAL SOLUTION:

  1. You have to add: compile 'io.netty:netty-all:4.0.24.Final' to the build.gradle file. (Example for netty JAR-Libary)
  2. I copy the Libary (netty) to an Folder called "libs" in my main Folder not in sry and so on. Create the folder if not exist
  3. Write your code and you will see, import works.

Thank you to José Pereda for the time and the final solution!

Upvotes: 2

Views: 1639

Answers (1)

José Pereda
José Pereda

Reputation: 45486

Based on the edited question, these are a few suggestions for working with dependencies on a JavaFXPorts project.

Dependencies and build.gradle file

According to this, the default dependency configurations compile and runtime are supported, and the jfxmobile plugin adds extra configurations for each supported platform like androidCompile or desktopRuntime.

To access third party dependencies, from a given repository this should be added:

repositories {  
   jcenter()   
}    
dependencies {
    compile 'groupId:artifactId:version'
}

Since jcenter() is a superset of 'mavenCentral()`, you can use any maven dependency that was in the form of:

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.json</artifactId>
    <version>1.0.4</version>
</dependency>

as compile 'groupId:artifactId:version'. So in this case:

dependencies {
    compile 'org.glassfish:javax.json:1.0.4'
}

Local files

Accesing local jars can be done using files:

dependencies { 
    compile files('lib/my-jar.jar') 
}

having my-jar.jar at a lib folder inside your project, but outside the src folder.

If you want to add several jars:

dependencies { 
    compile fileTree(dir: 'lib', include: ['*.jar']) 
}

Gluon plugin for NetBeans

After any change in the build.gradle file, it is necessary to reload the project, so the new changes are taken into account, and the new dependencies are retrieved.

Under the Projects view, right click on the Project root and select Reload Project.

Check also the Dependencies folders, those should contain the jars included in the build.

Since there are several of these folders, you can see for instance that Compile for android includes android.jarand jfxdvk-8u60-b3.jar. Compile for main should contain all the jars defined for compile.

Samples

These are some projects where the build.gradle contains dependencies, so they are a good way to start with JavaFXPorts.

Upvotes: 3

Related Questions