I started developing applications in Java + JavaFx a little over a month ago.
I was able to make a couple of beautiful animated applications. When compiling to a jar-file, I ran into the following problems:
Java17 doesn't run with jre which is for normal people, https://www.java.com/en/download/ , this begs the first question, why can't I develop on newer versions of java jdk without pain, why should I go down to version 8 and lose a lot of features
Also my javafx jars didn't want to run at all without any console messages (javafx unnamed .... @729347c ) and wouldn't run on double click. There were also messages like No runtime for favafx blah blah blah. I solved it by installing liberica jdk https://bell-sw.com/pages/downloads/#/java-17-lts. Now I can successfully compile jar files and run them by double clicking
I read right there, in a bunch of topics, that Oracle now means that I have to deliver to the clients the required version of jre (Jre17), the question is how can I do this. Newer versions of Lauch4j removed the ability to package jar along with jre. But I don't like Lauch4j either.
Later I learned about such thing as native-image in GraalVm. I tried compiling a jar file with javafx and it didn't work for me in any way. The program just crashed. And I found on the BellSoft website the package I needed https://bell-sw.com/pages/downloads/native-image-kit/#/nik-22-17, which has a configured graalvm. Thinking that these gods solved all my problems again, I compiled my jar file into an exe (yes, I changed the jdk in the environment paths). And Now I am getting Segment Fault message. But this is already better, at least it starts, although it crashes immediately after launch. Inside, by the way, the code of the usual default javafx program from Inteliji with the Hello javafx button
In general, I painted all the problems that I encountered. And I have 2 questions
My environment:
I will also clarify that I do not want to force clients to download anything (except perhaps https://www.java.com/en/download/, but no more), I want a completely native program
Sorry if it's messy
everything I tried and did is described above
I understand your frustration because properly packaging JavaFX applications is made mored complicated than it should be. There are a lot of tools that you have to combine which also leave much room for errors. The main problem is that the official OpenJFX Maven plugin (https://github.com/openjfx/javafx-maven-plugin) still doesn't have a packaging option. It has a Jlink goal but that does not help much in practice because it requires a fully modularised application which I have not yet seen in the wild for any serious project because many important libraries are not yet modular (and probably never will be).
Together with Dirk I have therefore created a demo project which combines jdeps, jlink and jpackage in a way that it can also handle non-modular projects and build an application and installer for all desktop platforms. Maybe you want to have a look at this repo: https://github.com/dlemmermann/JPackageScriptFX
You could also use Gluons GluonFX plugin (https://github.com/gluonhq/gluonfx-maven-plugin) which does contain a packaging option but that internally uses GraalVM native-image which requires some extra care to get it going and I personally never felt the need for this on desktop. It's the best option though if you also want to go mobile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With