Java9 packager with jlink compress tags
Asked Answered
G

2

5

when we create jlink runtime images we can use tags such as '--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages' , creating a distribution folder around 45mb.

If we want to use javapackager, for example to create an .DMG file, how can we do a similar compression? since these tags are not avaiable for javapackager. Without them the final bundle is around 100mb, losing a lot the java9 modularization advantages, so my question is if it is possible to use javapackager with JRE runtime images created by jlink.

thanks

Guru answered 14/11, 2017 at 13:45 Comment(0)
G
4

Answering my own question, we can just use the combination of two:

For MacOSX example:

1) generate a runtime dist with jlink, this will create a lib folder with around 50mb if you use compress tags.

2) Generate MacOSX.app with javapackager, this .app will come with a runtime lib folder around 98mb.

3) Simple replace them, right click MacOSX.app-> "show package contents", then go to Plugins/Java.runtime/Contents/Home/ and replace lib folder with the one generated by jLink.

This way you have a self-contained Java app with around 50mb instead of 100mb, thanks to beautiful Java9 modules.

Would be cool to do all of this just with javapackager, if it's possible I couldn't find how, I suggest to use something like gradle to execute all this process with 1 command.

Guru answered 15/11, 2017 at 16:7 Comment(0)
T
4

You can pass an option to the JDK 9 javapackager which is handed to the jlink process.

javapackager option to control jlink

-BjlinkOptions=compress=2
or
-BjlinkOptions=strip-debug

I could not figure out how to pass both at the same time.

-BjlinkOptions="compress=2 strip-debug"

lead to java.lang.IllegalArgumentException

-BjlinkOptions="strip-debug compress=2"

has the same result as -BjlinkOptions=strip-debug

When the option -BjlinkOptions=... is passed multiple times to javapackager, only the last one is taken into account.

The jlink options no-header-files and no-man-pages seems not valid here, as they lead to a NPE when passed after -BjlinkOptions=.

Territerrible answered 19/3, 2018 at 0:49 Comment(1)
javapackager parse jlinkOptions by Properties.load() method, so add a xml-escaped "\r\n" as sperator make sense: <argument>-BjlinkOptions=strip-debug &#xD;&#xA; compress=1</argument>Stinson

© 2022 - 2024 — McMap. All rights reserved.