The ResourceConfig instance does not contain any root resource classes

I have read other posts that mention this problem but that did not fix the problem.

I am trying to use jersey API for JAX-RS. but I have not been able to deploy it successfully.
I am using Eclipse IDE.
Also, I have added the required jars to classpath as well as lib folder.

  1. asm 3.1
  2. jersey server
  3. jersey core
  4. jersey servlet
  5. jersey quickstart webapp
  6. jsr311

web.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>restful</display-name>
<display-name>RESTfulWebServiceExample</display-name>  
  <servlet>  
    <servlet-name>Jersey REST Service</servlet-name>  
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>  
    <init-param>  
      <param-name>com.sun.jersey.config.property.packages</param-name>  
      <param-value>com.resttest.resttest</param-value>  
    </init-param>  
    <load-on-startup>1</load-on-startup>  
  </servlet>  
  <servlet-mapping>  
    <servlet-name>Jersey REST Service</servlet-name>  
    <url-pattern>/rest/*</url-pattern>  
  </servlet-mapping>  
</web-app>  

resttest.java is as follows:

package com.resttest;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

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

@Path("/calc")
public class resttest{

   @GET
   @Path("/add/{a}/{b}")
   @Produces(MediaType.TEXT_PLAIN)
   public String addPlainText(@PathParam("a") double a, @PathParam("b") double b) {
       return (a + b) + "";
   }

@GET
   @Path("/sub/{a}/{b}")
   @Produces(MediaType.TEXT_PLAIN)
   public String subPlainText(@PathParam("a") double a, @PathParam("b") double b) {
       return (a - b) + "";
   }

   @GET
   @Path("/add/{a}/{b}")
   @Produces(MediaType.TEXT_XML)
   public String add(@PathParam("a") double a, @PathParam("b") double b) {
       return "<?xml version="1.0"?>" + "<result>" +  (a + b) + "</result>";
   }

   @GET
   @Path("/sub/{a}/{b}")
   @Produces(MediaType.TEXT_XML)
   public String sub(@PathParam("a") double a, @PathParam("b") double b) {
       return "<?xml version="1.0"?>" + "<result>" +  (a - b) + "</result>";
   }
}


Source: java

Leave a Reply