How to create a modular JavaFX11 runnable jar/exe?

I have successfully followed the instructions mentioned in openjfx-docs (using maven)

I'm able to run it in my eclipse. I'm also able to create custom runtime images using jlink. The application could be run through the generated launcher.

Now, how do we create a runnable jar/exe with the stripped down JRE generated by jlink?

Upvotes: 3

Views: 1640

Answers (1)

Martin Mähly
Martin Mähly

Reputation: 71

I just recently started experimenting with the jlink tool of Java 11 and can provide a partial answer. The java command in the bin directory of a custom runtime image works just like java of the standard JRE:

/path/to/custom/runtime/image/bin/java -jar myjar.jar

The custom runtime image must of course contain all the required dependencies, which I made sure by making myjar.jar a modularized JAR and by providing the switch

--add-modules myjar.jar

when creating the custom runtime image with jlink. With the additional switch

--launcher mylaunchername=modulename.of.my.jar/mypackage.with.MainClass

the directly executable binary

/path/to/custom/runtime/image/bin/mylaunchername

is generated. On my Mac, I created an alias and moved that to the desktop. That's as close to an application as I could get so far, with the following caveats:

  • The app icon is the standard green "exec"
  • double clicking on this icon launches a terminal, which is undesirable in case of a JavaFX application
  • And, of course, the "application" is not a single file, but the complete custom runtime image folder.

Upvotes: 1

Related Questions