4

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

  • How can I distribute my javafx programs with my own jre like big companies do?
  • How to compile javafx program to native-image?

My environment:

  • Windows 10
  • Liberica Native Image Kit 22.3.0+2 (java17 jdk)
  • Latest version of Inteliji

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

Alex
  • 49
  • 1
  • 6
  • 5
    You should look at jpackage for generating self-contained applications. But in its simplest form, you can use jlink to generate a custom runtime image (including an equivalent of the JRE). See also https://openjfx.io/openjfx-docs/#modular. – Mark Rotteveel Dec 17 '22 at 08:35
  • 5
    Take a look at the "Packaging" section of the FAQs in the [JavaFX tag wiki](https://stackoverflow.com/tags/javafx/info). The [jpackage tool](https://docs.oracle.com/en/java/javase/17/jpackage/packaging-overview.html#GUID-E0966C49-ABBB-46A2-8DF7-1D3F96640F05) may be what you're looking for. – Slaw Dec 17 '22 at 08:47
  • 1
    The powers to be got so caught up in the modular stuff that they forgot simplicity. We got use to just focusing on the logic involved in our code. Lately, it's has been more difficult to get projects running and to create executables than writing code. – SedJ601 Dec 18 '22 at 22:01

1 Answers1

8

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.

mipa
  • 10,369
  • 2
  • 16
  • 35