'jaxb in jdk 11+, unable to resolve conflicts between javax.xml and jakarta.xml

Moving older project away from jdk8 I need to fix jaxb. Most of answers are for older versions, while I want to fix it to current versions and I'm kinda struggling with naming mess / dependency hell of javax.xml / jakarta.xml

I thought I moved away from saaj-impl 1.5.1 to newer 2.0.1 for for some reason during startup there is still search for com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl instead of com.sun.xml.messaging.saaj.soap.SAAJMetaFactoryImpl which is on classpath.

The produced message is:

javax.xml.soap.SOAPException: Provider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found

but I cannot figure out, how to stop this from kicking in. It seems, that library javax.xml.soap-api looks for javax.xml.soap.SAAJMetaFactory implementation, but configuration file for service loader is not present, so default will kick in. It's not present, because the service-loader file present on class path is jakarta.xml.soap.SAAJMetaFactory and not javax.xml.soap.SAAJMetaFactory. I'd guess that jaxws-api brings javax.xml.soap.api, which is then in conflict.

My post-jdk8 jaxb dependencies are:

  <dependency>
    <groupId>javax.xml.ws</groupId>
    <artifactId>jaxws-api</artifactId>
    <version>2.3.1</version>
  </dependency>
  <dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
  </dependency>
  <dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>3.0.2</version>
  </dependency>
  <dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>3.0.2</version>
  </dependency>
  <dependency>
    <groupId>com.sun.xml.messaging.saaj</groupId>
    <artifactId>saaj-impl</artifactId>
    <version>2.0.1</version>
  </dependency>

but this did not change a thing. So I tried replace jaxws-api with:

<dependency>
  <groupId>jakarta.xml.ws</groupId>
  <artifactId>jakarta.xml.ws-api</artifactId>
  <version>3.0.1</version>
</dependency>

<dependency>
  <groupId>jakarta.xml.soap</groupId>
  <artifactId>jakarta.xml.soap-api</artifactId>
  <version>3.0.0</version>
</dependency>

but that just makes tons of other classes missing. It's really cryptic and puzzling.

Can someone advise:

  • what is preferred nowadays? Jakarta or javax? What shall I aim for?
  • what is correct, winning combination of these dependencies with up-to-date versions? I don't want to see in dependencies something being 4y old.


Solution 1:[1]

I think I somehow resolved it, but part of resolution is not requesting newest versions. I almost made it work with newest libraries, but cannot overcome few conflicts. So, using springboot starter parent 2.6.6 I had to declare only following dependecies, which I taken from springs dependency management. But the biggest villan in my story was probably jaxb2-maven-plugin, which if you don't use version which is just right to be in sync with other can seemingly bring some dependencies, which will cause mess. Following version seems to be working along with shown dependencies, no extra dependencies are needed. When I tried to use plugin without version specified(taking it from spring parent), it didn't work for me, complaining about missing stuff.

Disclaimer: I have no trust in validity of following, while it seems to be working now. I didn't find any credible source of what is valid combination nor way how to find it myself. So I just shotgun debuged it so hard, wasted so much cpu cycles that seti@home could find at least 2 aliens with it.

jaxb2 plugin

<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>

Dependenies:

<dependency>
  <groupId>javax.activation</groupId>
  <artifactId>javax.activation-api</artifactId>
</dependency>

<dependency>
  <groupId>javax.xml.ws</groupId>
  <artifactId>jaxws-api</artifactId>
</dependency>

<dependency>
  <groupId>javax.xml.bind</groupId>
  <artifactId>jaxb-api</artifactId>
</dependency>

<dependency>
  <groupId>jakarta.xml.bind</groupId>
  <artifactId>jakarta.xml.bind-api</artifactId>
</dependency>

<dependency>
  <groupId>com.sun.xml.messaging.saaj</groupId>
  <artifactId>saaj-impl</artifactId>
</dependency>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martin Mucha