如何从maven依赖项构建java 9依赖项 [英] How to build java 9 dependencies from maven dependencies
问题描述
Java9引入了类似于OSGI和Maven Dependecies的强大模块性。
Java9 has introduced a strong modularity similar to OSGI and Maven Dependecies.
是否有maven插件能够构建检测maven依赖关系的java 9依赖项?
例如,来自
<groupId>com.mycompany.app</groupId>
<artifactId>my-module</artifactId>
....
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.3-jre</version>
</dependency>
到
module my-module{
requires com.google.guava;
exports com.mycompany.app;
}
我读过这篇文章,但它没那么有用 -
如何在maven上表达对java ee功能的依赖以转换到Java 9?
I have read this article, but it is not so useful - How to express dependency in maven on java ee features for transition to Java 9?
推荐答案
准确地回答这个问题, module-info
中的模块名称,如每个所说的 com.google.guava
一样被称为自动模块名称。一般来说,如果您已经为您的应用程序安装了一个带有Java 8的jar,那么请使用上面的maven配置说明 yourApp.jar
。您可以使用 jdeps
工具 as: -
To answer the question precisely, the names of modules in the module-info
as referenced in question like com.google.guava
per say are called the automatic module name. Generally, if you already have a jar with Java 8 for your app, let's say yourApp.jar
with the above maven configuration. You can make use of the jdeps
tool as:-
jdeps --generate-module-info <output-dir> /path/to/yourApp.jar
将生成模块信息.java
为你的jar,你可以在将同一个项目迁移到Java 9时进一步使用。
which would generate the module-info.java
for your jar that you can further make use of while migrating the same project to Java 9.
名称下的当前相应插件 maven-jdeps-plugin
似乎不支持这项任务。虽然它仍然可以正在进行的工作 in,如果所有者认为有效,将在Maven工作流程中引入。
The current corresponding plugin under the name maven-jdeps-plugin
does not seem to be supporting this task. Though its still Work in Progress and this might pitch in, if seen effective by the owners to be introduced in the Maven workflow.
编辑 :: 如果您发现任务有用,可以在 MJDEPS跟踪器。
Edit :: Just in case you find the task useful the feature can be requested at MJDEPS tracker.
这篇关于如何从maven依赖项构建java 9依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!