在java 9中使用jdeps为自动模块创建module-info [英] creating module-info for automatic modules with jdeps in java 9
问题描述
我有3罐杰克逊图书馆
- jackson-core-2.8.10.jar
- jackson-annotations-2.8.0.jar
- jackson-databind-2.8.10.jar
我成功地为core和annotation创建了module-info.java,并使用jdeps将它们转换为Named maodule。
I created module-info.java for both core and annotation successfully and converted them to Named maodule using jdeps.
对于databind,我尝试了以下命令:
for databind , I tried following command:
jdeps --generate-module-info。 --module-path%JAVA_HOME%\ jomds; jackson.core; jackson.annotations existingmods\jackson-databind-2.8.10.jar
jdeps --generate-module-info . --module-path %JAVA_HOME%\jomds;jackson.core;jackson.annotations existingmods\jackson-databind-2.8.10.jar
现在出现以下错误:
Missing dependence: .\jackson.databind\module-info.java not generated
Error: missing dependencies
com.fasterxml.jackson.databind.AnnotationIntrospector -> com.fasterxml.jackson.annotation.JsonCreator not found
com.fasterxml.jackson.databind.AnnotationIntrospector -> com.fasterxml.jackson.annotation.JsonCreator$Mode not found
com.fasterxml.jackson.databind.AnnotationIntrospector -> com.fasterxml.jackson.annotation.JsonFormat not found
com.fasterxml.jackson.databind.AnnotationIntrospector -> com.fasterxml.jackson.annotation.JsonFormat$Value not found
com.fasterxml.jackson.databind.AnnotationIntrospector -> com.fasterxml.jackson.annotation.JsonIgnoreProperties not found
com.fasterxml.jackson.databind.AnnotationIntrospector -> com.fasterxml.jackson.annotation.JsonIgnoreProperties$Value not found.
如何为jackson-databind生成module-info.java?
How can I generate module-info.java for jackson-databind ?
推荐答案
简短的回答是,是的,您必须将库转换为显式模块。
The short answer is that, yes, you'll have to convert the libraries to explicit modules.
jlink
工具旨在提供仅具有所需模块的修剪二进制图像。问题是自动模块可以访问可以读取所有JDK模块的类路径(也就是未命名的模块)。所以什么都不会被修剪。
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.
此主题也说明了这一点,并附有YouTube视频的链接。
This thread states this as well, with a link to a YouTube video.
此示例将 commons-lang3-3.5.jar
转换为用于 jlink
演示的explict模块。
This example converts commons-lang3-3.5.jar
to an explict module for a jlink
demo.
编辑:更具体,< a href =https://github.com/codetojoy/easter_eggs_for_java_9/tree/master/egg_34_stack_overflow_47727869\"rel =noreferrer>这是一个示例脚本,按顺序转换 jackson -core
, jackson-annotations
,以及 jackson-databind
传统罐到模块化罐子。
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.
这个想法是:
- 运行
jdeps - 传统jar上的-generate-module-info
- 将传统jar解压缩到fo lder,从上面添加
module-info.java
,重新编译并重新压缩
- 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
技巧是具有依赖关系的模块化jar将需要这些依赖项作为命令行参数。例如,这里是 jackson-databind
(略有抽象):
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
这篇关于在java 9中使用jdeps为自动模块创建module-info的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!