6

Environment: Win10, Oracle JDK 9, Eclipse, jlink, javapackager

Context: I'm trying to generate an executable file with javapackager having a java custom runtime image made with jlink, reading the javapackager documentation. Not an installable.

Jlink created a zip file, containing all my java class files and resources encapsulated (it means I don't have access to them from System Explorer) + the custom jre. It comes with a .bat launcher to run the app. All works fine.

Walkthrow: 1st I found out that there is a jpackage utility of OpenJDK available from OpenJDK14 to make java modular app executable, which is stil under development. I didn't find any way to work with that. Later I investigated Inno Setup, but it doesn't fulfil my needs (because I didn't want an installer) Later I discovered that since Oracle JDK 8 there is javapackager tool to generate runnables for each plattform (max, linux, windows..).

I'm not able to make javapackager work. This is one of various attempts of the command I executed on Windows cmd.

javapackager 
-deploy 
    -native exe
    --add-modules myModule,javafx.graphics,javafx.controls 
    --module-path "C:\path\to\javafx-jmods;C:\path\to\target\classes;C:\path\to\more\jmods" 
    -outdir "C:\myApp" 
    -outfile MyApp 
    -appclass myPackage.MyApp 
     -name "MyApp"

With the previous command I get the error:

Error: No application jars foun

So, I realized I was mixing the -deploy command and its options with the -createjar command and its options.

Can someone explain how to generate a .exe with javapackager?

Edit 1

Tried jpackage (using jdk 14 with Wix installer needed as dependency):

jpackage --package-type exe -o outputdir --name myApp --add-modules myapp,javafx.graphics,javafx.controls 
--module-path "C:\path\to\some\jmods;C:\path\to\myTarget;C:\path\to\javafx-sdk-11.0.2plugin" -m myapp/App

Output: myApp.1.0.exe. It opens a cmd and a "installer", but does not executes myApp as there is not the custom java runtime environment included.

tec
  • 999
  • 3
  • 18
  • 40
  • 1
    I'd recommend https://jdk.java.net/jpackage/ I use it regularly and it just works for me. What do you mean by: "I didn't find any way to work with that." – mipa Jul 19 '19 at 11:20
  • 1
    @mipa Because the jpackage download comes with an incomplete version of the OpenJDK14, not with just the jpackage.jar or whatever. I do not how to use it. Could you please add your usage in an answer? – tec Jul 19 '19 at 11:27

2 Answers2

2

If your project is build using Gradle then you can easly use the Badass jlink plugin: https://github.com/beryx/badass-jlink-plugin to build an installer / package using jpackage

Here's an artilce how to build an app image using OpenJDK 11 and using OpenJDK 14 with jpackage only for building the installer / package: https://walczak.it/blog/distributing-javafx-desktop-applications-without-requiring-jvm-using-jlink-and-jpackage

Adam from WALCZAK.IT
  • 1,339
  • 12
  • 11
  • Thanks for your answer, but I'm using Maven. I don't remember how, but I already accomplished to get an executable installer ( I I'm looking only for an executable). I will take up again this post another time. – tec Nov 13 '19 at 07:37
0

Install the JDK provided with jpackage like any JDK and set your JAVA_HOME to it.

As a preparation for the packaging I have instructed Maven to copy all dependent jar files of the project into the installer/input folder.

Then go to the main folder of your project and call

$JAVA_HOME/bin/jpackage \
--name yourAppName \
--output installer/output \
--input installer/input \
--main-jar yourAppMain.jar \
--main-class xxx.yyy.yourAppMainClass

The result should now be in the installer/output folder.

For more detailed information about the options you can call

$JAVA_HOME/bin/jpackage --help

There is also an option to use a different JDK with the jpackager but this is more advanced.

mipa
  • 10,369
  • 2
  • 16
  • 35
  • I arranged to generate an exe file (adding my app .jmod), but it does nothing because it doesn't have the jre included. The result of jlink is a custom runtime environment, stil don't know how to include that. – tec Jul 22 '19 at 08:22
  • If you followed my above instructions and the prerequisites of the documentation for your platform then you should get an exe WITH an included runtime. If not, there is something wrong with your setup. – mipa Jul 22 '19 at 08:35
  • Indeed, the result are 3 folders (app,bin,runtime) with an executable inside bin folder, but is there a way to have an exe file packaging those 3 folders? Tried --package-type command but it makes an installer. I need it just to run. – tec Jul 22 '19 at 12:08
  • Did you try the exe in the bin folder? It should contain everything. On my Mac I only get an app-folder which is the equivalent of an exe-file on windows. – mipa Jul 22 '19 at 15:30