title: ServletException: No servlet class has been specified
body: <p>I have what should be an extremely simple "Hello World" servlet, but I cannot get it to work. I am using Eclipse, Tomcat 8, Java 7, and Servlet 3.1.</p>
  
  <p>I have looked at many tutorials and questions, but they have not completely helped. Most tutorials I have seen talk about creating servlets by extending HttpServlet. I got those to work. Now I'd like to try the cleaner annotation approach.</p>
  
  <p>I've been referring to this tutorial, but it isn't quite complete and seems to have some incorrect or incomplete examples:
  <a href="http://docs.oracle.com/cd/E24329_01/web.1211/e24983/configure.htm#RESTF179" rel="noreferrer">Packaging and Deploying RESTful Web Services</a></p>
  
  <p>Why is com.testing.service.MyApplication not being loaded?</p>
  
  <p>Any help on getting this thing to run would be immensely appreciated!</p>
  
  <p>Here are my files:</p>
  
  <p>MyApplication.java</p>
  
  <pre><code>package com.testing.service;
  
  import java.util.HashSet;
  import java.util.Set;
  
  import javax.ws.rs.ApplicationPath;
  import javax.ws.rs.core.Application;
  
  @ApplicationPath("app")
  public class MyApplication extends Application {
      public Set&lt;Class&lt;?&gt;&gt; getClasses() {
          Set&lt;Class&lt;?&gt;&gt; s = new HashSet&lt;Class&lt;?&gt;&gt;();
          s.add(HelloWorldResource.class);
          return s;
      }
  }
  </code></pre>
  
  <p>HelloWorldResource.java</p>
  
  <pre><code>package com.testing.service;
  
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  
  @Path("/helloworld")
  public class HelloWorldResource {
      @SuppressWarnings("unused")
      private static final long serialVersionUID = 1L;
  
      @GET
      @Produces("text/plain")
      public String sayHello() {
          return "Hello World!";
      }
  }
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app
      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/web-app_3_1.xsd"
      version="3.1"&gt;
    &lt;display-name&gt;service&lt;/display-name&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;com.testing.service.MyApplication&lt;/servlet-name&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;javax.ws.rs.Application&lt;/param-name&gt;
          &lt;param-value&gt;com.testing.service.MyApplication&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
  
  &lt;/web-app&gt;
  </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/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;com.testing&lt;/groupId&gt;
    &lt;artifactId&gt;service&lt;/artifactId&gt;
    &lt;version&gt;1.0&lt;/version&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;
    &lt;name&gt;Rest Test&lt;/name&gt;
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
        &lt;artifactId&gt;javax.ws.rs-api&lt;/artifactId&gt;
        &lt;version&gt;2.0.1&lt;/version&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;  
    &lt;build&gt;
      &lt;pluginManagement&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;3.1&lt;/version&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;/pluginManagement&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Whenever I run Tomcat, it displays the following error:</p>
  
  <pre><code>INFO: Marking servlet com.testing.service.MyApplication as unavailable
  Feb 05, 2015 3:28:55 PM org.apache.catalina.core.StandardContext loadOnStartup
  SEVERE: Servlet /service threw load() exception
  javax.servlet.ServletException: No servlet class has been specified for servlet com.testing.service.MyApplication
      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1041)
      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4944)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5230)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
      at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:744)
  </code></pre>