--add-modules 仅在编译时 [英] --add-modules only on compilation

查看:49
本文介绍了--add-modules 仅在编译时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 maven 和 .我在我的 pom.xml 文件中添加了:

I'm building my project with maven and java-9. I've added in my pom.xml file:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>${maven-compiler-plugin.version}</version>
    <configuration>
        <source>${java.version}</source>
        <target>${java.version}</target>
        <compilerArgs>
            <arg>--add-modules</arg>
            <arg>java.xml.bind</arg>
        </compilerArgs>
    </configuration>
</plugin>

但是,要运行应用程序,我必须像这样运行它:

But still, to run the application I have to run it like this:

java -jar --add-modules java.xml.bind my-app.jar

有没有办法构建应用程序,从没有 --add-modules java.xml.bind 的命令行运行到 java 命令行参数?

Is there a way to build the application, to run from the command line without --add-modules java.xml.bind to java command line arguments?

推荐答案

我在不久前制作了这个答案回答这个问题作为使用 Maven 在 Java-9 中公开非 java.se 包的附加信息.

I made this answer a while ago where I answered this as an additional info to exposing non java.se packages in Java-9 using Maven.

添加的部分特别侧重于使用独立版本的java.xml.* API.为了适应这种情况,您可能可以开始使用对 jaxb-api:2.3.0 可以作为模块加载,也可以从类路径中执行.您需要进行的更改是将以下内容添加到您的依赖项列表中:

The added part specifically focusses on using the standalone version of the java.xml.* APIs. To adapt to which you can probably start consuming the dependency on jaxb-api:2.3.0 which can 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>

通过这种方式,您可以确保迁移到模块的独立 API 并远离 不推荐使用的一段代码.

This way you ensure migrating to standalone APIs for the module as well as moving away from a deprecated piece of code.

这篇关于--add-modules 仅在编译时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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