+-
java – 有没有办法在使用maven-jlink-plugin时添加maven依赖项?
我正在使用这个 Github project来接触Java 9中的新模块化功能.我想为项目添加依赖项并能够构建本机映像.但是,当我尝试向pom.xml添加新的依赖项,并将requires语句添加到module-info.java时,我从maven-jlink-plugin中收到以下错误:

Error: module-info.class not found for joda.time module

我正在尝试使用它作为概念证明,我可以使用新的链接阶段部署图像,但自然我需要能够具有外部依赖性,我需要使用maven(工作约束).

对mod-jar / pom.xml的更改

...
 <dependencies>
    <dependency>
      <groupId>joda-time</groupId>
      <artifactId>joda-time</artifactId>
      <version>2.9.9</version>
    </dependency>
  </dependencies>
...

MOD-罐/ module-info.java

module com.soebes.nine.jar {
  requires java.base;
  requires joda.time;
  exports com.soebes.example.nine.jar;
}

日志:

[INFO] --- maven-jlink-plugin:3.0.0-alpha-1:jlink (default-jlink) @ mod-jlink ---
[INFO] Toolchain in maven-jlink-plugin: jlink [ /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin/jlink ]
[INFO] The following dependencies will be linked into the runtime image:
[INFO]  -> module: com.soebes.nine.one ( /Users/sebastianrestrepo/Projects/jdk9-jlink-jmod-example/maven-example/mod-1/target/jmods/com.soebes.nine.one.jmod )
[INFO]  -> module: com.soebes.nine.two ( /Users/sebastianrestrepo/Projects/jdk9-jlink-jmod-example/maven-example/mod-2/target/jmods/com.soebes.nine.two.jmod )
[INFO]  -> module: com.soebes.nine.jar ( /Users/sebastianrestrepo/Projects/jdk9-jlink-jmod-example/maven-example/mod-jar/target/com.soebes.nine.jar-1.0-SNAPSHOT.jar )
[INFO]  -> module: joda.time ( /Users/sebastianrestrepo/.m2/repository/joda-time/joda-time/2.9.9/joda-time-2.9.9.jar )
[ERROR] 
Error: module-info.class not found for joda.time module
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] parent ............................................. SUCCESS [  1.460 s]
[INFO] com.soebes.nine.one ................................ SUCCESS [  2.022 s]
[INFO] com.soebes.nine.two ................................ SUCCESS [  1.392 s]
[INFO] com.soebes.nine.jar ................................ SUCCESS [  1.388 s]
[INFO] mod-jlink .......................................... FAILURE [  1.061 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.911 s
[INFO] Finished at: 2017-11-03T15:27:35-04:00
[INFO] Final Memory: 26M/981M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jlink-plugin:3.0.0-alpha-1:jlink (default-jlink) on project mod-jlink: 

我真的很感激任何帮助.谢谢.

最佳答案
这有 not much to do with the plugin I believe.模块joda.time在你的情况下似乎是一个自动模块.

jlink tool does not support linking of automatic modules因为它们可以依赖于类路径的任意内容,这违背了自包含Java运行时的想法.

所以有两种方法可以解决这个问题: –

>(你没有拥有jar)暂时继续创建一个module-info.java [你可以use jdeps tool为它]并使用相应的编译类更新jar [使用jar工具],就像在Java 9下的项目一样.
>(您拥有依赖项)永久地将jar迁移到Java 9本身,在编译和打包之后它将由module-info.class组成.

点击查看更多相关文章

转载注明原文:java – 有没有办法在使用maven-jlink-plugin时添加maven依赖项? - 乐贴网