title: Proper way to use Spring JAXB Marshaller with Java 9 without defining additional modules
body: <p>To illustrate my issue, I created a small spring boot sample application. The purpose of the application is to create a <code>Jaxb2Marshaller</code> bean.</p>
  
  <pre><code>@SpringBootApplication
  public class App implements CommandLineRunner {
  
      public static void main(String[] args) {
          SpringApplication.run(App.class, args);
      }
  
      @Bean
      public Jaxb2Marshaller jaxb2Marshaller() {
          Jaxb2Marshaller bean = new Jaxb2Marshaller();
          bean.setContextPath("ch.sahits.game.helloworld");
          return bean;
      }
  
      @Override
      public void run(String... args) throws Exception {
          System.out.println("Started up");
      }
  }
  </code></pre>
  
  <p>This code fails to start up with the exception:</p>
  
  <pre><code>Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
      at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
      at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
      at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:174)
      ... 23 more
  </code></pre>
  
  <p>What I do not understand about this exception is why the <code>com.sun.xml.internal.bind.v2.ContextFactory</code> is tried to instantiate? <a href="https://stackoverflow.com/questions/49480092/how-to-replace-add-modules-java-xml-ws">It has been suggested</a>, that I also need a dependency for a runtime, so I added:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.glassfish.jaxb&lt;/groupId&gt;
      &lt;artifactId&gt;jaxb-runtime&lt;/artifactId&gt;
      &lt;version&gt;2.3.0&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>But that only got me a different exception, trying to load a different class:</p>
  
  <pre><code>Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.model.annotation.AnnotationReader
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
      ... 39 more
  </code></pre>
  
  <p>Here is the complete <code>pom.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;ch.sahits.game&lt;/groupId&gt;
      &lt;artifactId&gt;AddModuleDependencies&lt;/artifactId&gt;
      &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
  
      &lt;properties&gt;
          &lt;cxf-xjc-plugin.version&gt;2.3.0&lt;/cxf-xjc-plugin.version&gt;
      &lt;/properties&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
              &lt;version&gt;2.0.0.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-oxm&lt;/artifactId&gt;
              &lt;version&gt;5.0.4.RELEASE&lt;/version&gt;
              &lt;scope&gt;compile&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
              &lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
              &lt;version&gt;2.3.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.annotation&lt;/groupId&gt;
              &lt;artifactId&gt;javax.annotation-api&lt;/artifactId&gt;
              &lt;version&gt;1.3.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jaxb&lt;/groupId&gt;
              &lt;artifactId&gt;jaxb-runtime&lt;/artifactId&gt;
              &lt;version&gt;2.3.0&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;resources&gt;
              &lt;resource&gt;
                  &lt;directory&gt;src/main/resources&lt;/directory&gt;
              &lt;/resource&gt;
          &lt;/resources&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.7.0&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;9&lt;/source&gt;
                      &lt;target&gt;9&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
                  &lt;artifactId&gt;cxf-xjc-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${cxf-xjc-plugin.version}&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;generate-sources&lt;/id&gt;
                          &lt;phase&gt;generate-sources&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;xsdtojava&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;extensions&gt;
                                  &lt;extension&gt;org.apache.cxf.xjcplugins:cxf-xjc-dv:${cxf-xjc-plugin.version}&lt;/extension&gt;
                              &lt;/extensions&gt;
                              &lt;xsdOptions&gt;
                                  &lt;xsdOption&gt;
                                      &lt;xsd&gt;src/main/resources/helloworld.xsd&lt;/xsd&gt;
                                      &lt;bindingFile&gt;src/main/resources/jaxb-binding.xjb&lt;/bindingFile&gt;
                                      &lt;packagename&gt;ch.sahits.game.helloworld&lt;/packagename&gt;
                                  &lt;/xsdOption&gt;
                              &lt;/xsdOptions&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>The simple solution of course is to add <code>--add-modules java.xml.ws</code> as a VM option, but that is exactly what I am trying to get rid off to make my application future proof.
  What dependency do I have to use to resolve this issue? Or do I have change the bean configuration, so that the proper classes are looked up (and not the ones from <code>com.sun.xml...</code> )?</p>
  
  <p>The MCVE for <a href="http://www.sahits.ch/download/AddModuleDependencies.zip" rel="nofollow noreferrer">download</a> as zip archive.</p>