I was asked to make a small program to help a friend's company for quickly writing out forms. It's a basic Swing program with some additional libraries added for Excel exporting.
I've completed the project and the program is only about 18 MB in size. However, using jpackage to create a standalone EXE for use balloons that all the way to 145 MB. The Java "runtime" folder in the resulting export from JPackage is 126 MB by itself. Here is the command I used, I kept it pretty simple:
jpackage ^
--type app-image ^
--input "C:\Users\Anon\Desktop\input" ^
--dest "C:\Users\Anon\Desktop\output" ^
--app-version 1.0 ^
--name "Billing System" ^
--main-jar "program.jar" ^
--main-class com.billingsystem.BillingProgram
I've read that it's possible to have the runtime only contain the essentials for the program (thus lowering the size of the folder), but I couldn't find a clear tutorial on it. I know that it uses modules, but I don't have any experience with them, since I've never personally had a need for them.
Preferably, I'd like to find a solution that's a small quick fix, rather than a long and involved one. Does anyone know how a quick way to define what I need?
Thank you for your time. Specific example showcases you can provide help immensely.
CodePudding user response:
For a modular jar file, the needed modules are taken from the jar's module-info.class
file. But, when using the --main-jar
option of jpacakge
a default set of modules is used. This can include more modules than the program actually needs, and there can also be missing modules. This is likely the main cause of the size of your "runtime" folder.
If you want a more trimmed down set of modules to be used, they need to be specified to jpackage
manually using --add-modules
.
To find all the modules that a jar file depends on you can use jdeps
with --print-module-depts
:
jdeps --print-module-deps <main jar>
(Note that if you have dependencies besides the JDK, you will also need to specify a module path)
This will print a comma-separated list of modules that you can then pass to jpackage
using --add-modules
:
jpackage --add-modules <module list> <other options>