Java9 packager with jlink compress tags

南楼画角 提交于 2019-12-06 02:43:02

问题


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


回答1:


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.




回答2:


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=.



来源:https://stackoverflow.com/questions/47287429/java9-packager-with-jlink-compress-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!