Take the 2-minute tour ×

There are other people asking this question, but the answers they got aren't working for me. I'm running a Jersey rest server as discussed in this link in Tomcat 7. My Resource class is Hello as shown below:

package com.rest.videos;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

public class Hello {
// This method is called if TEXT_PLAIN is request
  public String sayPlainTextHello() {
    return "Hello Jersey";

  // This method is called if XML is request
  public String sayXMLHello() {
    return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";

  // This method is called if HTML is request
  public String sayHtmlHello() {
    return "<html> " + "<title>" + "Hello Jersey" + "</title>"
        + "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";


My web.xml file is the following:


Whenever I visit the URL http://localhost:8080/Videos/rest/hello, it returns 404. I have an index.html file in my WEB-INF directory and if I go to http://localhost:8080/Videos/ where I assume it should be since the welcome-file-list says so, I also get a 404.

What am I doing wrong?

share|improve this question
where is /Videos prefix configured? Is that WAR part of an EAR w/ a <context-root>? –  TheArchitect Oct 10 '12 at 23:38
So my fault is that the Context root of the application was /Rest and so the proper url to use was localhost:8080/Rest/rest/hello. The display-name attribute in the web-xml has nothing to do with that. –  Sotirios Delimanolis Oct 10 '12 at 23:39

2 Answers 2

up vote 1 down vote accepted

Ok, I'll post an answer then if you don't mind giving credits :)

web.xml has not bearing on the URI path, so unless your WAR is wrapped into an EAR w/ a of /Videos, this prefix is invalid and likely is the root of your 404s.

share|improve this answer

Based on the tutorial you referred to, it seems you should try the following:

Notice the base URI the client code is using?

private static URI getBaseURI() {
    return UriBuilder.fromUri("http://localhost:8080/de.vogella.jersey.first").build();
  • com.rest.videos refers to the package name
  • /rest refers to the servlet-mapping in web.xml
  • /hello refers to the @Path annotation
share|improve this answer
Kind of. I called my Project Rest instead of the name of the packaage as given in the tutorial. When you create a dynamic web project in eclipse, it sets the context root of the app to /the-name-of-the-app. So the uri in the tutoriaal doesn't refer to any mapping in the web.xml, but to the context root of the app. This works regardless of the package name or class name you choose to give to your project resources. –  Sotirios Delimanolis Oct 11 '12 at 0:29

Your Answer


