如何在Java ee功能上表达对maven的依赖,以便过渡到Java 9? [英] How to express dependency in maven on java ee features for transition to Java 9?

查看:133
本文介绍了如何在Java ee功能上表达对maven的依赖,以便过渡到Java 9?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用 maven 并且具有依赖于其他内部工件的工件。我正在迁移到 java-9 ,并打算首先将所有内容迁移到Java 9而不模块化代码(即在未命名的模块中)。

We use maven and have artifacts that in turn depend on other internal artifacts. I am in the process of migrating to java-9, and intend to migrate everything to Java 9 first without modularizing the code (i.e. in the unnamed module).

我遇到的问题是我们依赖 java.xml.bind ,现在不包含在默认模块。是否有一种正确的方式来表达对Maven的 java.xml.bind 的依赖?

The problem I run into is that we depend on java.xml.bind, which is now not included in the default modules. Is there a "correct" way to express this dependency on java.xml.bind with Maven?

推荐答案

模块系统讲述了未命名模块的方式。从类路径加载应用程序的情况构造模块图。此外,从文档本身: -

The Module System speaks of the way the unnamed modules as in your case of loading the application from classpath constructs the module graph. Further, from the documentation itself:-


当编译器在未命名的模块中编译代码,或者调用java
启动程序时并且应用程序的主类从类路径加载
到应用程序类
loader的未命名模块,然后未命名模块的默认根模块集是
计算如下:

When the compiler compiles code in the unnamed module, or the java launcher is invoked and the main class of the application is loaded from the class path into the unnamed module of the application class loader, then the default set of root modules for the unnamed module is computed as follows:


  • java.se 模块是一个根,如果它存在。如果它不存在那么
    每个 java。* 模块在升级模块路径上或者系统
    模块中导出至少有一个包没有资格,是
    root。

  • The java.se module is a root, if it exists. If it does not exist then every java.* module on the upgrade module path or among the system modules that exports at least one package, without qualification, is a root.

每个非升级模块路径上的java。* 模块或者系统
模块 exports 至少有一个包没有资格,是
也是根。

Every non-java.* module on the upgrade module path or among the system modules that exports at least one package, without qualification, is also a root.

否则,默认的根模块集取决于阶段:

Otherwise, the default set of root modules depends upon the phase:


  • 在编译时,通常是编译的模块集(下面更多
    );

  • At compile time it is usually the set of modules being compiled (more on this below);

在链接时它是空的;和

在运行时它是应用程序的主模块,通过
- 模块(或简称-m)启动器选项。

At run time it is the application's main module, as specified via the --module (or -m for short) launcher option.

有时需要将模块添加到默认值以
为单位设置root,以确保模块图中将出现特定的平台,库或服务提供者
模块。在任何阶段,选项

It is occasionally necessary to add modules to the default root set in order to ensure that specific platform, library, or service-provider modules will be present in the module graph. In any phase the option

- add-modules< module>(,< module>)* 其中< module> 是模块名称,将命名模块添加到默认的根模块集。

--add-modules <module>(,<module>)* where <module> is a module name, adds the named modules to the default set of root modules.

jetty.project 中遇到类似问题来自jdk邮件列表的主题相同,修复是使用:

Similar issue was faced in jetty.project where a thread from jdk mailing list discussed over the same and the fix was to use:

--add-modules java.se.ee

为他们提供了访问所有Java SE模块的权限,在您的情况下只需:

which provided them access to all Java SE modules and in your case shall simply be:

--add-modules java.xml.bind

要在maven中使用它,你可以使用

To use this in maven, you can embed the same to the maven-compiler-plugin using

<compilerArgs>
    <arg>--add-modules</arg>
    <arg>java.xml.bind</arg>
</compilerArgs>

此处

需要注意的一点是,标记弃用API也意味着你可能想要远离使用它。为了适应这种方式,您可能开始消耗依赖于 jaxb-api:2.3.0 现在可以作为模块加载,也可以从类路径执行。您需要做的更改是将以下内容添加到依赖项列表中:

An important point to note is that marking deprecation of an API also means you might probably want to get away from using it. To adapt to this way you can probably start consuming the dependency on jaxb-api:2.3.0 which can now be loaded as a module and can be executed from the classpath as well. The change you need to make is to add the following to your dependencies list:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>






更新 : - 最后,随着Java-10的推出和接下来的JDK / 11,理想情况下应该遵循 JEP 320:删除Java EE和CORBA模块并进一步用它们的独立库替换这些依赖项。


Update:- Eventually, with Java-10 already out and JDK/11 up next, one should ideally follow the link to JEP 320: Remove the Java EE and CORBA Modules and further replace such dependencies with their standalone libraries instead.

这篇关于如何在Java ee功能上表达对maven的依赖,以便过渡到Java 9?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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