In our application we sometimes get the following exception:
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
We already found out that this happens only if we use Collection.parallelStream()
but not if we use Collection.stream()
.
We saw that JAXB uses Thread.currentThread().getContextClassLoader()
for loading classes. We also saw, that when using parallelStream()
, the threads for executing our command are using different class loaders. Sometimes it's a org.apache.catalina.loader.WebappClassLoader
, and sometimes it's a jdk.internal.loader.ClassLoaders.AppClassLoader
.
And it now seems, that the AppClassLoader
does not know about the JAXB dependencies, whereas the WebappClassLoader
does.
We are using Java 11 and the following Maven dependencies:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
Any idea what could be wrong? How can it be, that the AppClassLoader
does not know about our dependencies?