2

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!

Steinliiippp
  • 373
  • 4
  • 20
  • Could you be more specific or post your build.gradle file? Once you have the required dependencies, you can use them in your main code package, like in any other regular project. If you have platform specific dependencies, then those will be only available on that platfrom package. – José Pereda Jul 11 '15 at 14:37
  • I habe add the dependencies, but if i try to import it in my class, it says that the package is not there . . . normaly i say right click add Jar/libary and then i can use it, but there is no option to import these libarys. I copyed them in the libs folder under Android but the same ... Have you ever worked with javafxports? Can you tell me your way to import external libarys in netbeans? – Steinliiippp Jul 13 '15 at 11:38
  • I have a few projects you can check... [2048FX](https://github.com/jperedadnr/Game2048FX) or [HelloCharm](https://github.com/jperedadnr/HelloCharm). For starters I'll have a look at this one: [SMSTracker](https://github.com/jperedadnr/SMSTracker), there you'll see how the build.gradle is defined, and the structure of folders. Try to fork it, and run it and then let me know. – José Pereda Jul 13 '15 at 11:42
  • Ok i will do this ... but you have understood, that i want to use external libarys like apache common and so on? Will write back after i testet SMSTracker . . . – Steinliiippp Jul 13 '15 at 12:41
  • Ok i have one more question, maybe it awnser all :) Have you write this in build.gradle: dependencies { compile "com.gluonhq:charm-down-common:$CHARM_DOWN_VERSION" desktopRuntime "com.gluonhq:charm-down-desktop:$CHARM_DOWN_VERSION" androidRuntime "com.gluonhq:charm-down-android:$CHARM_DOWN_VERSION" iosCompile "org.robovm:robovm-cocoatouch:1.0.0" iosRuntime "com.gluonhq:charm-down-ios:$CHARM_DOWN_VERSION" } to use this in code? import com.gluonhq.charm.down.common.PlatformFactory; – Steinliiippp Jul 13 '15 at 12:45
  • Sure, otherwise it wouldn't work. All the dependencies outside the JDK have to be added to the build file, and then you can simply use them with a regular import. – José Pereda Jul 13 '15 at 13:39
  • Ok and this is exactly my problem could you tell my which statment i have to write unter dependencys to use external jar like apache commons in the lib folder of my project? Currently i use compile fileTree(dir: lib, include: *.jar) – Steinliiippp Jul 13 '15 at 13:46
  • Including his: `dependencies { compile 'org.apache.commons:commons-lang3:3.4' }` will add `commons-lang3-3.4.jar` to your project, and now you can import any of its classes on your main package: `import org.apache.commons.lang3.ArrayUtils;`. – José Pereda Jul 13 '15 at 13:51
  • Ok wow nice THANK YOU. I will test it at home :) Can you tell me one more pls. In which directory i have to put my JAR-Libary? in the lib folder? Cuz you only give the name of the Jar and not the Path ... – Steinliiippp Jul 13 '15 at 13:53
  • If you mean local dependencies, you can add them also like: `dependencies { compile files('lib/my-jar.jar) }`, having `my-jar.jar` at a `lib` folder inside your project. If you want to add several jars: `dependencies { compile fileTree(dir: 'lib', include: ['*.jar']) }`. – José Pereda Jul 13 '15 at 13:57
  • Ok yes i mean, that my dependencie is local on the phone. Great Thank you. I will test it at home and i hope you dont kill me if i ask you something to this again ... :) Wish you a nice day! – Steinliiippp Jul 13 '15 at 14:01
  • Ok, I'll put our comments in terms of a proper answer – José Pereda Jul 13 '15 at 14:02
  • Ok i tried it but it dont work ... pls look at my Question ... i add additional informations for you. Thank you for help! – Steinliiippp Jul 13 '15 at 14:42
  • First of all, use a `libs` folder outside src. Also you can add your dependencies via `compile 'io.netty:netty-all:4.0.24.Final` – José Pereda Jul 13 '15 at 14:45
  • Ok i tried it with compile 'io.netty:netty-all:4.0.24.Final' but i dosent work. No its download some .pom files for netty but it still shows the same error during import ... – Steinliiippp Jul 13 '15 at 14:50
  • After any changes on the dependencies, you have to Reload the project, so they are updated. On Projects view, right click on your project and select `Reload Project`. – José Pereda Jul 13 '15 at 14:51
  • Ok now it work ... sry for this loooong meeting :) Thank you very mutch for your help. I will write the final solution in my Question for all other users. – Steinliiippp Jul 13 '15 at 14:57
  • Glad it works, anyway, I am going to write a proper answer. – José Pereda Jul 13 '15 at 15:16
  • If it's related to the same topic, go ahead, otherwise start a new question – José Pereda Jul 13 '15 at 15:44
  • One last question: i tried to download gson from google but i dont get the right URL: 'com.google:code:gson:gson.2.3.1' Can you give me the right url? – Steinliiippp Jul 13 '15 at 15:52
  • Based on this: ` com.google.code.gson gson 2.3.1 ` it should be `groupId:artifactId:version`, so: `com.google.code.gson:gson:2.3.1` – José Pereda Jul 13 '15 at 15:55
  • There you go, I've added a full answer. Now you know how it works, but surely it will be useful for others... – José Pereda Jul 13 '15 at 22:13

1 Answers1

3

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.

Community
  • 1
  • 1
José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • For you who use eclipse and gluon - that wants as little trouble as possible. Look at the example of Local files - and also remember to right click project, add build path and select jar - just like normal. Both are required. – Lealo Sep 01 '17 at 20:18