Java 9 deprecated six modules that contain Java EE APIs and they are going to be removed soon:
javax.activation
pack
I have experimented with most of the suggestions described above using JDK 11.0.3 and have been not been successful. The only solution that I eventually found to work is the following. Perhaps there are other options that also work but it appears that the selection of version is critical. For example, changing com.sun.xml.ws:rt to 2.3.2 causes module javax.jws to no long be available.
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.4.0-b180830.0438</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>rt</artifactId>
<version>2.3.1</version>
</dependency>
I found the easiest path to get around the JAXB parts of these issues was to use dependency management in my root pom or in my bom:
<project ...>
<dependencyManagement>
<dependencies>
<!-- ... -->
<!-- Gone from jvm in java11 -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-ri</artifactId>
<version>2.4.0-b180830.0438</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<!-- ... -->
</dependencies>
</dependencyManagement>
</project>
And in the modules that fail compilation on jdk11:
<!-- ... -->
<dependencies>
<!-- Gone from jvm in java11 -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<scope>runtime</scope>
</dependency>
<!-- ... -->
</dependencies>
<!-- ... -->
Also, updating the version of org.jvnet.jaxb2.maven2:maven-jaxb2-plugin
to 0.14.0 solved all the jaxb generation issues for me.
JAXB (java.xml.bind) for JDK9
Working perfectly in my desktop applications on jdk9/10 EA
<properties>
<jaxb-api.version>2.3.0</jaxb-api.version>
</properties>
<!-- JAXB 2.3.0 for jdk9+ -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${jaxb-api.version}</version>
</dependency>
<!-- JAXB needs javax.activation module (jdk9) -->
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>
Just a minor variation (improvement) on the above answers --- exemplified here for JAXB only. One can add the dependencies with the runtime
scope and only if this is effectively needed (i.e. when building for running in a JRE with version >= 9 --- here v11 is exemplified):
<profile>
<id>when-on-jdk-11</id>
<activation>
<jdk>11</jdk>
</activation>
<properties>
<!-- missing artefacts version properties -->
<jaxb-api.version>2.3.1</jaxb-api.version>
<jaxb-impl.version>2.3.2</jaxb-impl.version> <!-- one might let it the same with the jaxb-api.version -->
</properties>
<dependencies>
<!-- runtime dependencies to avoid JAXB related CNF exceptions when running on Java 11 (e.g.: ClassNotFoundException: javax.xml.bind.annotation.XmlType) -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${jaxb-impl.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
I needed to replace JAX-WS (java.xml.ws) and JAXB (java.xml.bind) for my Spring Boot 2 based application and ended up with these JARs (Gradle build):
// replacements for deprecated JDK module java.xml.ws
runtimeOnly 'javax.xml.ws:jaxws-api:2.3.0' // javax.xml.ws.* classes
runtimeOnly 'javax.jws:jsr181-api:1.0-MR1' // for javax.jws.* classes
// replacement for deprecated JDK module java.xml.bind
runtimeOnly 'javax.xml.bind:jaxb-api'
runtimeOnly 'org.glassfish.jaxb:jaxb-runtime:2.3.0.1'
runtimeOnly 'org.glassfish:javax.json:1.1.2'
runtimeOnly 'org.eclipse:yasson:1.0.1'
(You may need compile
or other scope, runtimeOnly
was enough for us.)
I noticed that https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core is described as "Old" and using this answer went for org.glassfish
based stuff that brought in org.eclipse.yasson
as well.
Now it's really messy situation, it works, but how should anyone be sure it's the best replacement, right?
It seems that jaxws-ri depends transitively from commonj.sdo:commonj.sdo:jar:2.1.1.v201112051852 which apparently can be found from repository http://download.eclipse.org/rt/eclipselink/maven.repo