1

I did migrate my Maven based project to SpringBoot 2.0 and Java 9. In the process, I had to add some dependencies to get rid of Java 9 warnings regarding modules (that still can be added with --add-modules).

However I am unable to get rid off --add-modules java.xml.ws. As suggested in JEP 320, adding dependencies:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.3.0</version>
</dependency>

These dependencies allow to run mvn test to run through. The build from IntelliJ IDE also works.

However when starting the Spring Boot application, I get the following runtime exception:

...
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
    at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
    at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:174)
    ... 64 more

What Maven dependencies am I missing? JarFinder tells me that the implementation class is part of jaxb-impl, but only up to version 2.2.12. So where did this implementation disappear to?

hotzst
  • 7,238
  • 9
  • 41
  • 64

1 Answers1

1

You need also jaxb-runtime:

    <dependency>                                                            
        <groupId>org.glassfish.jaxb</groupId>                               
        <artifactId>jaxb-runtime</artifactId>                               
        <version>2.3.0</version>                                            
    </dependency> 

And I don't think you need any of the com.sun dependencies, use glassfish ones for the implementation:

    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>

As a side note, I think it is good to have at least one integration test (maven failsafe one) that starts the spring context. If you will have one make sure you use at least surefire and failsafe 2.21.0 (previous version had a bug with --add-modules).

Krzysztof Krasoń
  • 26,515
  • 16
  • 89
  • 115
  • Adding this module only causes another exception: `java.lang.NoClassDefFoundError: com/sun/xml/bind/v2/model/annotation/AnnotationReader`. For whatever reason classes are tried to load something from `com.sun.xml.bin.v2` – hotzst May 02 '18 at 16:47
  • I added a new question with a more complete example: https://stackoverflow.com/questions/50139996/proper-way-to-use-spring-jaxb-marshaller-with-java-9-without-defining-additional – hotzst May 02 '18 at 17:14