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

后端 未结 2 1562
有刺的猬
有刺的猬 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:32

    No, jlink requires all included modules to be explicit, meaning they need to have a module descriptor. Here's what the documentation says about the jlink's module path:

    The path where the jlink tool discovers observable modules. These modules can be modular JAR files, JMOD files, or exploded modules.

    Note the absence of "plain JARs" (i.e. JARs without descriptor).

    You can upgrade existing third-party JARs to modular JARs, though (with some effort). The steps are:

    • get the JAR and all its dependencies
    • create a module-info.java for it (either manually or with JDeps)
    • compile it to module-info.class with --patch-module to tell the compiler about the sources
    • use jar --update to add the module declaration to the existing JAR

    Alternatively, you can use a tool like ModiTect that does these things for you.

提交回复
热议问题