Java – ServletException: No servlet class has been specified


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.

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.

I've been referring to this tutorial, but it isn't quite complete and seems to have some incorrect or incomplete examples:
Packaging and Deploying RESTful Web Services

Why is com.testing.service.MyApplication not being loaded?

Any help on getting this thing to run would be immensely appreciated!

Here are my files:

package com.testing.service;

import java.util.HashSet;
import java.util.Set;


public class MyApplication extends Application {
    public Set<Class<?>> getClasses() {
        Set<Class<?>> s = new HashSet<Class<?>>();
        return s;

package com.testing.service;


public class HelloWorldResource {
    private static final long serialVersionUID = 1L;

    public String sayHello() {
        return "Hello World!";


<?xml version="1.0" encoding="UTF-8"?>



<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
  <name>Rest Test</name>

Whenever I run Tomcat, it displays the following error:

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(
    at org.apache.catalina.core.StandardWrapper.load(
    at org.apache.catalina.core.StandardContext.loadOnStartup(
    at org.apache.catalina.core.StandardContext.startInternal(
    at org.apache.catalina.util.LifecycleBase.start(
    at org.apache.catalina.core.ContainerBase$
    at org.apache.catalina.core.ContainerBase$
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$

Best Solution

I found the answer in the comments of a related question. The answer was provided by Alvin Thompson. Unfortunately, I don't have enough reputation to up-vote your answer.

If you're using a standard Tomcat install (or some other servlet container), you need to include a REST implementation since Tomcat doesn't come with one. If you're using Maven, add this to the dependencies section:


Then just add an application config class to your project. If you don't have any special configuration needs aside from setting the context path for the rest services, the class can be empty. Once this class is added, you don't need to configure anything in web.xml (or have one at all).

Originally posted here:

How to set up JAX-RS Application using annotations only (no web.xml)?