title: How to set up JAX-RS Application using annotations only (no web.xml)?
body: <p>Is it possible to set up a JAX-RS application using annotations only? (using Servlet 3.0 and JAX-RS Jersey 1.1.0)</p>
  
  <p>I tried and had no luck. Using some <code>web.xml</code> seems required.</p>
  
  <hr>
  
  <p><strong>Configuration A (working, but has web.xml configuration)</strong></p>
  
  <p>web.xml</p>
  
  <pre class="lang-xml prettyprint-override"><code>   ...
     &lt;servlet&gt;
        &lt;servlet-name&gt;org.foo.rest.MyApplication&lt;/servlet-name&gt;
     &lt;/servlet&gt;
     &lt;servlet-mapping&gt;
         &lt;servlet-name&gt;org.foo.rest.MyApplication&lt;/servlet-name&gt;
         &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
     &lt;/servlet-mapping&gt;
     ...
  </code></pre>
  
  <p>Java</p>
  
  <pre><code>@ApplicationPath("/")
  public class MyApplication extends Application {
      ...
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Configuration B (not working, exception thrown)</strong></p>
  
  <pre><code>@ApplicationPath("/")
  @WebServlet("/*") // &lt;-- 
  public class MyApplication extends Application {
      ...
  }
  </code></pre>
  
  <p>The latter seems to insist that the Application will be a subclass of Servlet (the exception leaves no guesswork)</p>
  
  <pre><code>java.lang.ClassCastException: org.foo.rest.MyApplication cannot be cast to javax.servlet.Servlet
  </code></pre>
  
  <hr>
  
  <p><strong>Questions</strong></p>
  
  <ol>
  <li><p>Why the web.xml definition worked but the annotation didn't? What's the difference?</p></li>
  <li><p>Is there a way to have it worked, e.g. have a JAX-RS Application with no web.xml?</p></li>
  </ol>