title: Using Moxy with Metro in tomcat
body: <p>due to company requirements we can't use Glassfish as application server. Nevertheless I would like to use Moxy. So I tried to get the new Metro-version (<a href="https://blogs.oracle.com/mgrebac/entry/metro_2_2_jaxb_2" rel="nofollow noreferrer">https://blogs.oracle.com/mgrebac/entry/metro_2_2_jaxb_2</a>) to work with a tomcat 7. I managed it to bootstrap Moxy using Spring like it is described in the metro documentation (<a href="http://metro.java.net/guide/user-guide.html#springa" rel="nofollow noreferrer">http://metro.java.net/guide/user-guide.html#springa</a>) but I didn't manage it to get it to work with Moxy.</p>
  
  <p>I've tried the solution mentioned in the metro documentation (<a href="http://metro.java.net/2.2/guide/ch17.html" rel="nofollow noreferrer">http://metro.java.net/2.2/guide/ch17.html</a>) and the solution mentioned here (<a href="https://stackoverflow.com/questions/13253874/use-moxy-as-default-jaxb-implementation">Use Moxy as default JAXB Implementation</a>). </p>
  
  <p>But the most I could get out of it was the following exception:</p>
  
  <pre><code>com.sun.xml.ws.spi.db.DatabindingException: Unknown JAXBContext implementation: class org.eclipse.persistence.jaxb.JAXBContext
      at com.sun.xml.ws.spi.db.BindingContextFactory.getJAXBFactory(BindingContextFactory.java:207)
      at com.sun.xml.ws.spi.db.BindingContextFactory.create(BindingContextFactory.java:149)
      at com.sun.xml.ws.message.jaxb.JAXBMessage.create(JAXBMessage.java:160)
      at com.sun.xml.ws.fault.SOAPFaultBuilder.createSOAP11Fault(SOAPFaultBuilder.java:423)
      at com.sun.xml.ws.fault.SOAPFaultBuilder.createSOAPFaultMessage(SOAPFaultBuilder.java:200)
      at com.sun.xml.ws.fault.SOAPFaultBuilder.createSOAPFaultMessage(SOAPFaultBuilder.java:188)
      at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:391)
      at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:640)
      at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:263)
      at com.sun.xml.ws.transport.http.servlet.ServletAdapter.invokeAsync(ServletAdapter.java:218)
      at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:159)
      at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:194)
      at com.sun.xml.ws.transport.http.servlet.WSSpringServlet.doPost(WSSpringServlet.java:52)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p>My test webservice was:</p>
  
  <pre><code>@WebService
  public class TestService {
      public String sayHello() throws JAXBException {
          System.out.println(org.eclipse.persistence.Version.getVersion());
          JAXBContext c = JAXBContext.newInstance(TestPojo.class);
          return "Hello";
      }
  }
  </code></pre>
  
  <p>And yes the the moxy jars (org.eclipse.persistence.moxy-2.4.0.jar, org.eclipse.persistence.core-2.4.0.jar, org.eclipse.persistence.asm-3.3.1.v201206041142.jar) are on the classpath.</p>
  
  <p>Thx for help</p>
  
  <p>JayBee</p>