creating module-info for automatic modules with jdeps in java 9

Deadly 提交于 2019-11-28 07:52:33

The short answer is that, yes, you'll have to convert the libraries to explicit modules.

The jlink tool is intended to provide a trimmed binary image that has only the required modules. The issue is that automatic modules have access to the classpath (aka the unnamed module) which can read all JDK modules. So nothing would be trimmed.

This thread states this as well, with a link to a YouTube video.

This example converts commons-lang3-3.5.jar to an explict module for a jlink demo.

Edit: to be more specific, here is an example script that converts, in order, jackson-core, jackson-annotations, and jackson-databind legacy jars to modular jars.

The idea is:

  • run jdeps --generate-module-info on the legacy jar
  • unzip the legacy jar into a folder, add module-info.java from above, re-compile, and re-zip

The trick is that modular jars with dependencies will require those dependencies as command-line parameters. For example, here is jackson-databind (abstracted somewhat):

# here, jackson-core and jackson-annotations have been built
# jackson-databind 

jdeps --module-path $ROOT_DIR/modules \
--add-modules jackson.annotations,jackson.core \
--generate-module-info work $JACKSON_DATABIND_JAR

javac --module-path $ROOT_DIR/modules \
--add-modules jackson.annotations,jackson.core \
-d $ROOT_DIR/classes module-info.java
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!