我有一个依赖于自动模块的显式模块化项目;例如在 java.activation 上。仍然可以使用jlink吗?
请参阅此模块信息.java:
module hello {
requires java.activation;
}
那么jlink无法添加模块:$ jlink --module-path target/modules --add-modules hello --output target/jlink
Error: automatic module cannot be used with jlink: java.activation from file:///C:/Development/jlinkExample/target/modules/javax.activation-api-1.2.0.jar
据我了解,自动模块无论如何都会包含整个类路径。所以我想用 jlink 创建运行时镜像没有任何好处?另见:What is an automatic module?
有没有可能规避这个问题?也许为这些依赖项生成一个 module-info.java ?
最佳答案
From my understanding an automatic module would contain the whole classpath anyway, so I guess there would be no benefit in creating a runtime-image with jlink?
不,自动模块不会包含整个类路径。事实上,没有明确定义为模块的工件(包含
module-info.java
)但可以在 上找到。模块路径 被视为自动模块以弥合显式模块和类路径代码之间的差距。Are there any possibilities to circumvent this issue, maybe generating a module-info for those dependencies?
是的,您可以 create a
module-info.java
with jdeps
或使用 moditect 之类的插件为模块生成模块信息并将其注入(inject)现有的 JAR。一旦工件(JAR) 有明确的模块声明,
jlink
应该毫无失败地接受它。
关于java - 将 jlink 与自动模块一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52518105/