How to package app at Java 11 with non-modular dependencies

Update: jpackage is now included since JDK 14. The following answer is still applicable for older JDK versions, though.


I've had the same issue. I wanted to use JDK 11, but according to JDK-8212780 JEP 343 is scheduled for JDK 13, so we'll need to wait a little longer. Packaging "native" self-contained applications under Java 8 - 10 wasn't a problem, since the packager was included (at least in the Oracle JDK).

Today I found out about this email and figured I'd like to give it a try: You can see my sample project on github.com/skymatic/javafx11-test, which I successfully packaged using the back-ported jpackager from the JDK development branch.

What I did here:

  • Created a new HelloWorld project using OpenJDK 11 and OpenJFX 11.
  • Downloaded the packager and invoke it from the Maven build (note it needs to reside with the JDK and you need to set JAVA_HOME for it to work...)
  • Bonus: I used jdeps to find out the dependency of my non-modular jar and set the --add-modules parameter to produce a smaller runtime image

Of course it is even easier for modular projects: In this commit to my sample project you can see that I used jpackager's parameters for the module path and main module instead of the classpath and main class.