title: How to resolve JAXB classpath issues on Java 12
body: <p>Im porting application using JAXB to JDK 11/12 but am completely lost when trying to fix those JAXB classpath issues. I have googled and read basically everything related to this so Im aware of the changes made in Java11, i.e. removal of JAXB from JDK ... However in that case I would assume a trivial fix consisting of adding api and impl JARs on classpath. But this is not working and despite I have those JARs on classpath Im still getting the known exception, despite using 2.3.2 JAXB:</p>
  
  <blockquote>
    <p>javax.xml.bind.JAXBException
       - with linked exception:
      [java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]</p>
  </blockquote>
  
  <p>even if I see the class is in different package and I instruct to use correct package via system variable it does not work either:</p>
  
  <p>gradle -Djavax.xml.bind.context.factory=com.sun.xml.bind.v2.ContextFactory build</p>
  
  <blockquote>
    <p>javax.xml.bind.JAXBException
       - with linked exception:
      [java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]</p>
  </blockquote>
  
  <p>Does anyone have clue how to resolve this? I dont want to play with manifest files etc. It should be possible to just place the right JARs on classpath and that is it, or not? </p>
  
  <p>Summary here but unable to get it working:
  <a href="http://www.descher.at/descher-vu/2019/01/java-11-jaxb-and-osgi/" rel="noreferrer">http://www.descher.at/descher-vu/2019/01/java-11-jaxb-and-osgi/</a></p>
  
  <p>Update, dependencies used in Gradle:
  - jaxb-xjc has jaxb-runtime (impl.) as transitive dependency. I see it is picked by Gradle but still the same error.</p>
  
  <pre><code>classpath "com.sun.activation:javax.activation:1.2.0"
  classpath "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
  classpath "org.glassfish.jaxb:jaxb-xjc:2.3.2"
  classpath"org.glassfish.jaxb:jaxb-core:2.3.0.1"
  </code></pre>
  
  <blockquote>
    <p>[org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Resolve jaxb-runtime.jar (org.glassfish.jaxb:jaxb-runtime:2.3.2)' completed</p>
    
    <p>[org.gradle.internal.component.model.ComponentAttributeMatcher] Selected match org.glassfish.jaxb:jaxb-runtime:2.3.2 configuration runtime from candidates [org.glassfish.jaxb:jaxb-runtime:2.3.2 configuration runtime] for {org.gradle.dependency.bundling=external, org.gradle.jvm.version=12, org.gradle.usage=java-runtime}</p>
  </blockquote>
  
  <p>This is output of "gradle dependencies" and all the JAXB jars are there, still classpath error is being thrown. The JAR file jaxb-runtime from Glassfish for sure has this ContextFactory class.</p>
  
  <pre><code>runtimeClasspath - Runtime classpath of source set 'main'.
  +--- org.springframework.boot:spring-boot-starter-log4j2 -&gt; 2.1.0.RELEASE
  |    +--- org.apache.logging.log4j:log4j-slf4j-impl:2.11.1
  |    |    +--- org.slf4j:slf4j-api:1.7.25
  |    |    +--- org.apache.logging.log4j:log4j-api:2.11.1
  |    |    \--- org.apache.logging.log4j:log4j-core:2.11.1
  |    |         \--- org.apache.logging.log4j:log4j-api:2.11.1
  |    +--- org.apache.logging.log4j:log4j-core:2.11.1 (*)
  |    +--- org.apache.logging.log4j:log4j-jul:2.11.1
  |    |    \--- org.apache.logging.log4j:log4j-api:2.11.1
  |    \--- org.slf4j:jul-to-slf4j:1.7.25
  |         \--- org.slf4j:slf4j-api:1.7.25
  +--- org.projectlombok:lombok -&gt; 1.18.2
  +--- org.apache.commons:commons-lang3 -&gt; 3.8.1
  +--- org.apache.commons:commons-collections4 -&gt; 4.4
  +--- com.google.guava:guava -&gt; 23.0
  |    +--- com.google.code.findbugs:jsr305:1.3.9
  |    +--- com.google.errorprone:error_prone_annotations:2.0.18
  |    +--- com.google.j2objc:j2objc-annotations:1.1
  |    \--- org.codehaus.mojo:animal-sniffer-annotations:1.14
  +--- org.apache.ws.xmlschema:xmlschema-core -&gt; 2.0.1
  +--- org.glassfish.jaxb:jaxb-runtime:2.3.2
  |    +--- jakarta.xml.bind:jakarta.xml.bind-api:2.3.2
  |    |    \--- jakarta.activation:jakarta.activation-api:1.2.1
  |    +--- org.glassfish.jaxb:txw2:2.3.2
  |    +--- com.sun.istack:istack-commons-runtime:3.0.8
  |    |    \--- jakarta.activation:jakarta.activation-api:1.2.1
  |    +--- org.jvnet.staxex:stax-ex:1.8.1
  |    |    +--- jakarta.activation:jakarta.activation-api:1.2.1
  |    |    \--- jakarta.xml.bind:jakarta.xml.bind-api:2.3.2 (*)
  |    +--- com.sun.xml.fastinfoset:FastInfoset:1.2.16
  |    \--- jakarta.activation:jakarta.activation-api:1.2.1
  \--- org.glassfish.jaxb:jaxb-core:2.3.0.1
       +--- javax.xml.bind:jaxb-api:2.3.0 -&gt; 2.3.1
       |    \--- javax.activation:javax.activation-api:1.2.0
       +--- org.glassfish.jaxb:txw2:2.3.0.1 -&gt; 2.3.2
       \--- com.sun.istack:istack-commons-runtime:3.0.5 -&gt; 3.0.8 (*)
  </code></pre>