30

I'm building my project with maven and . 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

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?

wbk
  • 1,310
  • 2
  • 11
  • 19
  • what I think but maybe wrong, what you did in `maven-compiler-plugin` is just for compiler `javac` which is also used by maven to compile your project, but not for runtime `java`, so you had to add `--add-modules` to java runtime `java`. – Tiina Oct 09 '17 at 02:57
  • That's right, and That's why I've asked question how to run without adding `--add-modules`. – wbk Oct 09 '17 at 19:47

1 Answers1

43

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.

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>

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

Naman
  • 27,789
  • 26
  • 218
  • 353
  • I found [this Answer by bourgesl](https://stackoverflow.com/a/48279048/642706) enabled JAXB for me on Java 10. – Basil Bourque Jul 17 '18 at 22:21
  • @BasilBourque Well, the answer was to primarily focus on the `--add-modules` Vs direct dependencies of similar modules. Agreed over resolving JAXB, there is definitely an [additional step required](https://stackoverflow.com/questions/43574426) - the proper long-term solution suggested in the accepted answer. – Naman Jul 18 '18 at 06:18