Search code examples
javajava-9java-modulelaunch4jjlink

How to use launch4j with a Java custom runtime image?


Is it possible to make a bundle/wrapper exe file with Launch4j with a modular java app?

The app is modular (jmods), exported with jlink, it doesn't generate any jar, but a custom runtime image (a few folders) with a bat file that runs the command: java -m package/path.to.class

I read Launch4j docs, it sais jar tag is optional. Tried to use the program with the gui (it doesn't even enable the Run button) and with Windows cmd (launch4j: Application jar doesn't exist.)

Edit 1:

This SO post is related to my question. Launch4j does not have this functionality yet.

Solution (until no other tool is capable to do so):

  • Make the 7z file with the java custon runtime image:

    7z a "outputPath\fileName.7z" "inputPath\javaCustomImgFolder"
    
  • Make a config.txt file with these params:

    ;!@Install@!UTF-8!
    Title="Your app name" //dont know where it's shown.
    BeginPrompt="Do you want to install This Program?" //same
    RunProgram="your.exe" //7z automatically search a .exe
    Directory="bin" //play with the path if you need to
    ;!@InstallEnd@!
    
  • Genearte the exe file:

    copy /b "path\7zS2.sfx" + "path\config.txt" + "pathTo\fileName.7z"   outputName.exe
    

Note: I needed the 7zS2.sfx (27kb) version file, which I've found here by reference of this SO post. Other versions didn't make the job for me.


Solution

  • As far as I know, none of the exe building tools predating the Java modules has caught up yet.

    In case of Launch4j, there’s a feature request, but there is no visible progress report. So we can only guess when it will be done.

    But since jlink can create a bundled app with launcher script, a generic generator for self extracting archive files, like WinZip or 7zip, see also How do I make a self extract and running installer, could be sufficient.

    These generators for self-extracting archives usually also allow to specify a program/script to run after extraction, so when we archive the bundled application and specify the launch script, we get an exe file that can run a bundled modular Java application with a double-click. Which is the best we can get so far, until better solutions arrive.