Java 9: Generating a runtime image with JLink using 3rd party jars

后端 未结 2 1564
有刺的猬
有刺的猬 2020-12-30 12:38

I\'d like to create a Java 9 runtime image that contains 3rd party jars. I have made a simple Java project (let\'s call this Example) to call a utility jar (let

2条回答
  •  死守一世寂寞
    2020-12-30 13:30

    jlink directly can not do this. The trick is to call jdeps on all external libs to collect their system module dependencies and than modify the parameters to jlink accordingly. Generating a module-info.java will not always work to solve the problem but you can use jdeps to see what system modules you need and than create a custom Java Runtime with jlink which includes all these system dependencies and put the external libs on the classpath or module path dependening on if they are non-modular jars or automatic module jars.

    You can use something like a special maven plugin to automate that task.

提交回复
热议问题