title: Java 11: Implementation of JAXB-API has not been found on module path or classpath
body: <p>I have a little project which does throw an exception when i let it run.</p>
  
  <p>The problem is here (TestObject.java):</p>
  
  <pre><code>final JAXBContext jaxbContext = JAXBContext.newInstance(...);
  </code></pre>
  
  <p>I really do not understand why this throws the exception. I also created a test which works like a charm (TestTest.java). Please forgive me the names, but this is just a small test application to get this working with java 11.</p>
  
  <p>I followed this: <a href="https://stackoverflow.com/questions/51916221/javax-xml-bind-jaxbexception-implementation-of-jaxb-api-has-not-been-found-on-mo">javax.xml.bind.JAXBException Implementation of JAXB-API has not been found on module path or classpath</a>
  and added </p>
  
  <pre><code>compile('javax.xml.bind:jaxb-api:2.3.0')
  compile('javax.activation:activation:1.1')
  compile('org.glassfish.jaxb:jaxb-runtime:2.3.0')
  </code></pre>
  
  <p>to my build.gradle but then it complains that </p>
  
  <pre><code>Error:java: module not found: java.activation
  </code></pre>
  
  <p>is missing. As this is also removed from Java 11 i added:</p>
  
  <pre><code>compile 'com.sun.activation:javax.activation:1.2.0'
  </code></pre>
  
  <p>but then it throws a lot of errors:</p>
  
  <pre><code>Error:java: the unnamed module reads package com.sun.xml.bind from both jaxb.runtime and jaxb.core
  Error:java: the unnamed module reads package com.sun.xml.bind.util from both jaxb.runtime and jaxb.core
  Error:java: the unnamed module reads package com.sun.xml.bind.marshaller from both jaxb.runtime and jaxb.core
  Error:java: the unnamed module reads package com.sun.xml.bind.api from both jaxb.runtime and jaxb.core
  Error:java: the unnamed module reads package com.sun.xml.bind.v2 from both jaxb.runtime and jaxb.core
  Error:java: the unnamed module reads package com.sun.xml.bind.v2.util from both jaxb.runtime and jaxb.core
  Error:java: the unnamed module reads package com.sun.xml.bind.v2.model.impl from both jaxb.runtime and jaxb.core
  Error:java: the unnamed module reads package com.sun.xml.bind.v2.model.annotation from both jaxb.runtime and jaxb.core
  Error:java: the unnamed module reads package com.sun.xml.bind.v2.runtime from both jaxb.runtime and jaxb.core
  Error:java: the unnamed module reads package com.sun.xml.bind.v2.runtime.unmarshaller from both jaxb.runtime and jaxb.core
  Error:java: the unnamed module reads package com.sun.xml.bind.unmarshaller from both jaxb.runtime and jaxb.core
  Error:java: module jaxb.runtime reads package com.sun.xml.bind from both jaxb.core and jaxb.runtime
  Error:java: module jaxb.runtime reads package com.sun.xml.bind.util from both jaxb.core and jaxb.runtime
  Error:java: module jaxb.runtime reads package com.sun.xml.bind.marshaller from both jaxb.core and jaxb.runtime
  Error:java: module jaxb.runtime reads package com.sun.xml.bind.api from both jaxb.core and jaxb.runtime
  Error:java: module jaxb.runtime reads package com.sun.xml.bind.v2 from both jaxb.core and jaxb.runtime
  Error:java: module jaxb.runtime reads package com.sun.xml.bind.v2.util from both jaxb.core and jaxb.runtime
  Error:java: module jaxb.runtime reads package com.sun.xml.bind.v2.model.impl from both jaxb.core and jaxb.runtime
  Error:java: module jaxb.runtime reads package com.sun.xml.bind.v2.model.annotation from both jaxb.core and jaxb.runtime
  Error:java: module jaxb.runtime reads package com.sun.xml.bind.v2.runtime from both jaxb.core and jaxb.runtime
  Error:java: module jaxb.runtime reads package com.sun.xml.bind.v2.runtime.unmarshaller from both jaxb.core and jaxb.runtime
  Error:java: module jaxb.runtime reads package com.sun.xml.bind.unmarshaller from both jaxb.core and jaxb.runtime
  Error:java: module jaxb.core reads package com.sun.xml.bind from both jaxb.core and jaxb.runtime
  </code></pre>
  
  <p>What is so confusing to me: the test works. So it seems like there is some kind of jaxb-implementation in the junit5 environment. 
  I also found some other information in how to migrate a java 8 app to java 9 modules, where i found this:</p>
  
  <pre><code>compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.4.0-b180830.0359'
  compile group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.4.0-b180830.0438'
  compile group: 'org.glassfish.jaxb', name: 'jaxb-xjc', version: '2.4.0-b180830.0438'
  </code></pre>
  
  <p>But this is also not working. I would be very happy if someone can help me to get that running.
  I use java-openjdk-11.0.1.13-11.rolling.fc29.x86_64 on Fedora 29, 64 bit.</p>
  
  <p>ps.: i wanted to write all that into the comment of the post with topic "javax.xml.bind.JAXBException..." but i was not allowed to do so. So i created this new post.</p>
  
  <p>edit: the exception which is thrown in that sample application is this:</p>
  
  <pre><code>Exception in thread "main" java.lang.RuntimeException: 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.bind.v2.ContextFactory]
      at test/com.example.TestObject.doSomething(TestObject.java:21)
      at test/com.example.TestObject.main(TestObject.java:12)
  Caused by: 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.bind.v2.ContextFactory]
      at java.xml.bind/javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:269)
      at java.xml.bind/javax.xml.bind.ContextFinder.find(ContextFinder.java:412)
      at java.xml.bind/javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
      at java.xml.bind/javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
      at test/com.example.TestObject.doSomething(TestObject.java:17)
      ... 1 more
  Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
      at java.xml.bind/javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
      at java.xml.bind/javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
      at java.xml.bind/javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:267)
      ... 5 more
  </code></pre>