有没有办法在使用 maven-jlink-plugin 时添加 maven 依赖项? [英] Is there a way to add maven dependencies while using the maven-jlink-plugin?

查看:43
本文介绍了有没有办法在使用 maven-jlink-plugin 时添加 maven 依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这个 Githubproject 以了解 Java 9 中的新模块化功能.我想向项目添加依赖项并能够构建本机映像.但是,当我尝试向 pom.xml 添加新的依赖项,并将 requires 语句添加到 module-info.java 时,我从 maven-jlink-plugin 收到以下错误:

I'm using this Github project to get exposed to the new modular features in Java 9. I would like to add dependencies to the project and be able to build a native image. However, when I try to add a new dependency to the pom.xml, and add the requires statement to the module-info.java, I get a the following error from the maven-jlink-plugin:

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

我试图将其用作我可以使用新链接阶段部署图像的概念证明,但自然而然我需要能够拥有外部依赖项,并且我需要使用 maven(工作约束).

I'm trying to use this as a proof of concept that I can deploy images using the new linking phase, but naturally I need to be able to have external dependencies and I need to use maven (work constraint).

修改 mod-jar/pom.xml

Changes to mod-jar/pom.xml

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

mod-jar/module-info.java

mod-jar/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: 

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

I would really appreciate any help. Thanks.

推荐答案

这有 我认为与插件没有太大关系.在您的情况下,模块 joda.time 似乎是一个自动模块.

This has not much to do with the plugin I believe. Module joda.time in your case seems to be an automatic module.

jlink 工具不支持链接自动模块,因为它们可以依赖类路径的任意内容,这与自包含 Java 运行时的想法背道而驰.

The jlink tool does not support linking of automatic modules because they can rely on the arbitrary content of the classpath, which goes against the idea of a self-contained Java runtime.

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

So there are two ways to fix this probably :-

  • (你不拥有这个 jar)暂时继续创建一个 module-info.java[你可以 使用 jdeps 工具] 并使用相应的编译类更新 jar[使用 jar 工具],就像在 Java 9 下的项目中一样.

  • (you don't own the jar) Temporarily go ahead create a module-info.java[you could use jdeps tool for it] and update the jar[using jar tool] with the corresponding compiled class as in projects under Java 9.

(您拥有依赖项)将 jar 永久迁移到 Java 9 本身,在编译和打包后它将由 module-info.class 自身组成.

(you own the dependency) Permanently migrate the jar to Java 9 itself, where it would consist of the module-info.class by itself after being compiled and packaged.

这篇关于有没有办法在使用 maven-jlink-plugin 时添加 maven 依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆