Search code examples
eclipsejerseytomcat8

Tomcat cannot find class for my REST web service class


I create a simple web service using Eclipse WTP. Tomcat version is 8.5 and Java is 1.8.

I downloaded Jersey 2.27. When starting the Server from Eclipse, I receive the following error:

java.lang.RuntimeException: A class file of the class name, my.simple.webservice.SimpleWebService is identified but the class could not be found.

Any helps to resolve this is very much appreciated.

Searching on StackOverflow and other site did not return any useful information.

My web service looks like this:

 package my.simple.webservice;

    ...imports ...

    @Path("/")

    public class SimpleWebService {

    @POST

    @Path("/service")

    @Consumes(MediaType.APPLICATION_JSON)

    public Response consumeService(InputStream incomingData) {
        /* 
                 *do stuff here with the JSON
                 */
        // return HTTP response 200 in case of success
        return Response.status(200).entity(myStringBuilder.toString()).build();
    }

    @GET
    @Path("/verify")
    @Produces(MediaType.TEXT_PLAIN)
    public Response verifyRESTService(InputStream incomingData) {
        String result = "My Simple web service Successfully started..";

        // return HTTP response 200 in case of success
        return Response.status(200).entity(result).build();
    }

}

My web.xml looks like this:

    <servlet-name>Jersey Web Application</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>my.simple.webservice</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

Solution

    1. Delete your project's build folder
    2. then clean install by maven build
    3. Run your application

    If it still does not work let me know, i will replicate the problem on my system.