8

Unfortunately the javapackager tool will be removed with JDK 11 - as it is part of JavaFX, which will also be removed. Hence, there will be no "official" and easy way to create native Java application bundles for Mac or Windows any longer.

I tried to re-use the native launcher files generated by Java 9/10's javapackager (on Mac: my.app/Contents/MacOS/my) and they still seem to work with JDK 11. However that's a bit of a dirty solution. Any ideas about how to natively package and launch applications with Java 11 and beyond (Mac platform preferred)?

José Pereda
  • 44,311
  • 7
  • 104
  • 132
Michael
  • 532
  • 1
  • 6
  • 15
  • 2
    A new tool is proposed to fill the gap: https://bugs.openjdk.java.net/browse/JDK-8200758 but it's not targeted for a specific release yet. – Jorn Vernee Sep 14 '18 at 13:56
  • Yes, I've seen that JEP already. So the necessity seems to be there, but no hope for a quick implementation. And it's also not sure that you will be able to use the OpenJDK packager/bundler to bundle an Oracle JDK. – Michael Sep 14 '18 at 14:16
  • 1
    As of JDK14 you can now use **`jpackage`** as shown here: https://stackoverflow.com/a/66511673/191246 (still incubating though) – ccpizza Mar 06 '21 at 23:41

2 Answers2

0

You can use the jlink command, which will bundle your modules into a custom runtime image. This is a bit different from javapackager though, requiring you to use modules for it to work properly. You might be able to get it working without modules if you manually specify all the modules from the JRE that are required.

apetranzilla
  • 5,331
  • 27
  • 34
  • Hi! I'm using jlink already to create a custom, as small as possible, JRE. However, jlink does not create a native launcher file. It has a launcher option, but that just creates a shell script, which does not behave like a native Mac app (e.g. wrong icon in Dock). javapackager, however, creates a native launcher file, which starts the bundled VM via native code. – Michael Sep 14 '18 at 14:14
  • Ah, I see. Aren't OSX applications basically special zips? If so, wouldn't it be pretty easy to write a script that bundles the necessary files and sets the icon and such? – apetranzilla Sep 14 '18 at 22:20
  • You are right in principle. Those .app bundles are no zips, but just special directory structures. It's indeed easy to create one by hand. However the crucial point is the *launcher* program, which must be a native program and should start the VM and the main class. – Michael Sep 15 '18 at 09:57
  • If you're feeling adventurous, it shouldn't be difficult to write a basic C program that launches your jar, or maybe even using GraalVM's [native-image](https://www.graalvm.org/docs/reference-manual/aot-compilation/) tool to compile the jar into an ELF binary? – apetranzilla Sep 15 '18 at 15:57
0

As ccpizza commented above:

As of JDK14 you can now use jpackage as shown here: stackoverflow.com/a/66511673/191246 (still incubating though) – ccpizza

Michael
  • 532
  • 1
  • 6
  • 15
  • Why is this the accepted answer? I found the question while googling for Java *11* bundling. The referred answer is about Java *14*. – stippi Oct 08 '21 at 14:34
  • The question does say: "Any ideas about how to natively package and launch applications with Java 11 *and beyond*" so it's quite relevant – h00ligan Mar 15 '23 at 08:24