I'm trying to create a native installer using jpackage for a relatively small program. The created app image is ~120 MB in size. This is odd since I used jlink before and the runtime image only used to be ~40 MB. After some digging, I found runtime/lib/modules
in my app image, a file 90 MB in size. As runtime/legal
lists a lot of things (modules?) I don't use, I think that jpackage packs things it shouldn't, but I'm not sure.
Note: The program isn't supposed to be modular. My understanding is that this is only useful when making multi-part programs or libraries. I used the module-info.java
that was autocreated by eclipse to, well, "trick" jlink into creating a runtime image.
Here are the args I use to create the app image.
--type app-image
--name myapp
--dest target\appimg
--temp target\appimg-work
--input target\jar
--icon .\icon.ico
--main-jar target\jar\myapp.jar
--main-class com.msgprograms.myapp.AppMain
After copying some files into the app image, I create the installer using another jpackage run, this time using these args:
--type msi
--app-version 0.0.1
--copyright "(C) msgprograms"
--description "some app"
--name myapp
--dest target
--temp target\installer-work
--vendor msg-programs
--app-image target\appimg\myapp
// omitted windows-specific args
Why is the app image so big and how do I make it smaller? Is there a way other than making the program modular again, creating a runtime image with jlink and then giving that to jpackage?
EDIT:
I forgot to mention that the app doesn't use JavaFX. All articles I found on jpackage do though, so they're of limited help only.
EDIT 2:
Trying to be clever by doing --jlinkoptions "--add-modules java.desktop"
doesn't work, as jlink option [--add-modules] is not permitted in --jlink-options
CodePudding user response:
JPackage does automatically use jlink to build a JRE, and those modules end up in that modules file. If your jar isn't modular then jpackage will be adding everything unless you set --add-modules
. Otherwise check module-info.java
only contains the essentials for your runtime, not any test code dependencies. Some versions of Eclipse I've used have been very keen to add JUNIT test libraries to module-info.java
which are not required in the deployment release directories. Eclipse should be set up with separated build directories for src test code.
However there are benefits to using jlink
independently as you can test your codebase with the JRE before using jpackage - this can save a lot of time and if your JDK dependencies are not changing the previously jlink
JRE is already prepared.
Also, the jlink command line supports addition flags to strip down the JRE size further:
jlink --strip-debug --no-man-pages --no-header-files --compress=1 --add-modules blah,blah --output myjre
CodePudding user response:
Have a look at this tutorial. https://github.com/dlemmermann/JPackageScriptFX It's also primarily made for JavaFX but the basic principles are general and would be helpful for you. It separates the jlink phase from the jpackage phase and thus makes it possible to completely avoid the module system but still be able to build a reduced runtime image.