title: Testing against Java EE 6 API
body: <p>I write an addition to JAX-RS and included the Java EE 6 API as a Maven dependency. </p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;javax&lt;/groupId&gt;
      &lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
      &lt;version&gt;6.0&lt;/version&gt;
      &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Then I have a little test case:</p>
  
  <pre><code>  @Test
    public void testIsWriteable() {
      class SpecialViewable extends Viewable {
        public SpecialViewable() {
          super("test");
        }
      }
      FreeMarkerViewProcessor processor = new FreeMarkerViewProcessor(null);
      assertTrue(processor.isWriteable(SpecialViewable.class, null, null,
              MediaType.WILDCARD_TYPE));
    }
  </code></pre>
  
  <p>But I get an error:</p>
  
  <pre><code>java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ws/rs/core/MediaType
      ...
  </code></pre>
  
  <p>If I include Jersey as a JAX-RS implementation instead of the Java EE API everything is fine.</p>
  
  <p>Thanks to BalusC's hint I know what I had guessed: Java EE 6 is only an API without method bodies:
  <a href="http://weblogs.java.net/blog/ludo/archive/2007/01/java_ee_5_apis.html" rel="noreferrer">From the java.net blog</a> </p>
  
  <blockquote>
    <p>You can compile you code with this
    jar, but of course you cannnot run
    your application with it since it
    contains only the Java EE 5 APIs and
    does not contain any method bodies. If
    you try to run, you would get this
    exception:</p>
    
    <p>Exception in thread "main"
    java.lang.ClassFormatError:   Absent
    Code attribute in method that is not
    native or abstract in class file
    javax/mail/Session</p>
    
    <p>In order to execute a Java EE 5
    application, you'll still need a Java
    EE 5 container, like for example the
    GlassFish application server.</p>
  </blockquote>
  
  <p>I've tried to add Jersy with <code>test</code> scope but it didn't work.</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;javax&lt;/groupId&gt;
      &lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
      &lt;version&gt;6.0&lt;/version&gt;
      &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
      &lt;artifactId&gt;jersey-server&lt;/artifactId&gt;
      &lt;version&gt;${jersey-version}&lt;/version&gt;
      &lt;scope&gt;test&lt;/scope&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>How can I test software that depends only on the official Java EE API?</p>
  
  <p><strong>Solution</strong></p>
  
  <p>The provider (Jersey) needs to be placed <em>before</em> the API (javeee-api) in the pom.xml.</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.sun.jersey&lt;/groupId&gt;
      &lt;artifactId&gt;jersey-server&lt;/artifactId&gt;
      &lt;version&gt;${jersey-version}&lt;/version&gt;
      &lt;scope&gt;test&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;javax&lt;/groupId&gt;
      &lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
      &lt;version&gt;6.0&lt;/version&gt;
      &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt;
  </code></pre>