--add-modules仅用于编译 [英] --add-modules only on compilation
问题描述
我正在使用maven和 java的9 。我在 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。*
蜜蜂。为了适应你可能开始消费依赖 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屋!