Java --add-modules only on compilation

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46220810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:17:00  来源:igfitidea点击:

--add-modules only on compilation

javamavenjaxbjava-9maven-compiler-plugin

提问by wbk

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

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

<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:

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

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

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

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

采纳答案by Naman

I made this answera while ago where I answered this as an additional info to exposing non java.sepackages in Java-9 using Maven.

I made this answera while ago where I answered this as an additional info to exposing non java.sepackages in Java-9 using Maven.

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.0which 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:

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.0which 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>

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

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