title: MOXy exceptions in JavaEE Jersey 2.0 project
body: <p>Im trying to implement Json support in a JavaEE project but had issues with MOXy related exceptions being generated. I read on jersey.java.net that MOXy should be autodiscoverable but it doesnt seem to work when i try.</p>
  
  <p>So to make this easy to pinpoint i just generated a new '<strong><em>jersey-quickstart-webapp</em></strong>' project and changed MyResource as below (my goal is to use an Application class instead of web.xml but this was the simplest way och pinpointing it. The error occurs no matter what).</p>
  
  <pre><code>@Path("myresource")
  public class MyResource {
          @GET
          @Produces(MediaType.APPLICATION_JSON)
          public Response getIt() {
              return Response.status(Response.Status.ACCEPTED).entity(new TestEntity()).build();
          }
      }
  </code></pre>
  
  <p>TestEntity class (in same package):</p>
  
  <pre><code>@XmlRootElement
  @XmlAccessorType(XmlAccessType.FIELD)
  public class TestEntity {
      private String content = "SOME CONTENT";
  
      public String getContent() {
          return content;
      }
  }
  </code></pre>
  
  <p>POM.xml:</p>
  
  <pre><code>&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/maven-v4_0_0.xsd"&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;a.b.c&lt;/groupId&gt;
      &lt;artifactId&gt;server&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;server&lt;/name&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;server&lt;/finalName&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.5.1&lt;/version&gt;
                  &lt;inherited&gt;true&lt;/inherited&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-bom&lt;/artifactId&gt;
                  &lt;version&gt;${jersey.version}&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-container-servlet-core&lt;/artifactId&gt;
              &lt;!-- use the following artifactId if you don't need servlet 2.x compatibility --&gt;
              &lt;!-- artifactId&gt;jersey-container-servlet&lt;/artifactId --&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-media-moxy&lt;/artifactId&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;properties&gt;
          &lt;jersey.version&gt;2.22.1&lt;/jersey.version&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>I deployed this on a clean Glassfish 4.1.1 using IntelliJ.
  After this i receive</p>
  
  <blockquote>
    <p>java.lang.ClassNotFoundException:
    javax.xml.parsers.ParserConfigurationException not found by
    org.eclipse.persistence.moxy</p>
  </blockquote>
  
  <p>So i add beans.xml as below (tried empty as well as i saw indicated in Oracle docs)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
         bean-discovery-mode="all"&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>And i get this error when deploying</p>
  
  <blockquote>
    <p>java.lang.NoClassDefFoundError: Could not initialize class
    org.eclipse.persistence.jaxb.BeanValidationHelper</p>
  </blockquote>
  
  <p>I tried , for fun, removing the web.xml, changing the dependency <strong><em>jersey-container-servlet-core</em></strong> to <strong><em>jersey-container-servlet</em></strong> and creating an Application class instead (as discussed in <a href="https://stackoverflow.com/questions/33291897/containerrequestfilter-wont-run-in-javaee-jersey-project">ContainerRequestFilter wont run in JavaEE jersey project</a>) but gives the same error. Infact it gives the same error if publishing a clean javaee-api 7.0 dependant project instead of jersey dependencies and gave same error (i suppose glassfish using jersey anyway).</p>
  
  <p>So i guess im missing something here, any kind soul that could fill me in on what? :) </p>