-
Notifications
You must be signed in to change notification settings - Fork 2
Bundle JAR into universal executables
The project is built using JDK 11
thus, launching it using previous Java version is impossible.
We recommend using JDK 11
for the following steps.
Tools used :
-
jdeps*
-
jlink*
* installed with JDK 11 for example
Java is now a modular platform, where you can create your own "JRE" distribution with specifically the modules that you need to run your application.
So instead of packing a full JDK folder beside the application, we'll create our own JRE folder containing all the modules we need.
We assume you have built or retreive the project's artifact .JAR Application
.
Next, go into the folder containing the artifact using your terminal.
$ jdeps --module-path lib/ --add-modules=ALL-MODULE-PATH --list-deps java-rdp.jar
It will return the list of modules which are used in our application.
Example:
java.base
java.desktop
We can now use the tool jlink
to create our JRE.
jlink --no-header-files --no-man-pages --add-modules <MODULE1>,<MODULE2>,... --output <CUSTOM JRE DIR>
Now, a <CUSTOM JRE DIR>
directory will be created! That's it !
Size of :
- full JDK 11 : 285 MB (👎)
- custom JRE : 72 MB (🥇)
Tools used :
Unfortunately, Launch4j doesn't wrap the JRE in the .exe application, you have to put it next to it. I will explain :
- Create a folder where you want, that's where we will be putting our application, we'll call it
<APP FOLDER>
. - Open Launch4j (Java 1.8.0 required i think)
- Choose your output file (in
<APP FOLDER>
)(don't forget to put .exe at the end...)
- Choose your JAR file
- Next, in the JRE tab, just type
<CUSTOM JRE DIR>
(for example, jre_custom if we named our custom JRE folder that way) - In the 'Classpath' tab, click on
Custom classpath
and choose the main class. - You can then put an icon, or version information but it's not necessary !
- Then, press the "settings" icon beside the run button. It will ask you to save a
.CFG
file, put it where you want and it'll generate the.EXE
app in<APP FOLDER>
- Next, copy the
<CUSTOM JRE DIR>
into the<APP FOLDER>
folder
Your <APP FOLDER>
should look like :
<APP FOLDER>:
|-- <CUSTOM JRE DIR>
|--bin/ (in bin there is java.exe)
|-- lib/
|-- <APP>.exe
Thus, you should be able to distribute the application and the client doesn't even need to have JDK installed.
You can launch the .JAR
application using command line using the custom JRE folder and binary.
Inside the application folder :
<CUSTOM JRE DIR>/bin/java --module-path lib/ --add-modules=ALL-MODULE-PATH -jar java-rdp.jar
Simply create a New Issue and I will try to help you.