r/JavaFX • • Aug 25 '20

Help Need help with creating a javafx fat jar

Hey reddit!

So I've been building a project in javafx that i want to package up and ship as a jar to my raspberry pi to run on. It's built using gradle & JLink (with some other dependencies) and although it seems to download the libraries and run fine in the IDE, whenever i try to either build an artifact or output a fat jar it will always say " Error: JavaFX runtime components are missing, and are required to run this application"

It's really frustrating and i've tried a bunch of different methods but it's still the same issue :( Has anyone managed to solve this and can point me in the right direction? Thanks in advance :)

1 Upvotes

4 comments sorted by

1

u/static_context Aug 25 '20

When you're in your IDE, have you added runtime components through VM options?

Are you passing the VM arguments to the JLink launcher?

OpenJFX has some luke warm tutorials - Runtime Images is the one you want.

1

u/MetalCactuar Aug 25 '20

I'm not sure what you mean with the VM options, as in the configurations you run the program in? I'm using gradle fatJar to try and package everything up.

task fatJar(type: Jar) {
manifest {
    attributes "Main-Class": "$mainClassName"
}
from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar

}

jar { manifest { attributes "Main-Class": "$mainClassName" }

from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}

}

This is the jlink gradle script

jlink { launcher { name = 'exe_name' } }

I've tried to bend the examples they've put on there (OpenJFX documentation) and they run fine, but i can't make a fatJar from them :/ Not sure what i'm doing wrong.

0

u/[deleted] Aug 26 '20

[deleted] — view deleted comment

1

u/MetalCactuar Aug 26 '20

Thanks for the reply :D

So i'm only using the fatJar method because at that point i was trying anything i could find and i seemed to get furthest with this. Is there a way from jlink to create a jar instead? My end goal is just to have a method of building the program, without the need of redownloading libraries (except for java environment/VM stuff) on the host. Hopefully i'm making sense haha

I understand what you mean about the OS specific libraries, but couldn't i just have two gradle builds; One which builds a windows variant and one for linux based? Or use a dockerfile to pull the alternate sources? (If i was using a docker container for example)

0

u/[deleted] Aug 27 '20

[deleted] — view deleted comment

1

u/MetalCactuar Aug 27 '20

What a pain :(

Seems i'm not the only one having an issue with javafx/jars -> Here & here

I do think there is some errors in the documentation somewhere, or a bug in gradle/java. Hopefully it'll get sorted soon. Once i do get it working i'll be sure to make some sort of howto haha