Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jersey servlet exception tomcat jersey

I'm having an issue trying to Deploy servlet to Tomcat using maven; I've been reading about this issue in other posts but still couldn't succeed with the answers/suggestions.

I'm getting this Exception no matter what i'm trying:

javax.servlet.ServletException: Servlet.init() for servlet Jersey Web Application threw exception org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745) root cause com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes. com.sun.jersey.server.impl.application.RootResourceUriRules.(RootResourceUriRules.java:99) com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1359) com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:180) com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:799) com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:795) com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193) com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795) com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790) com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:509) com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:339) com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605) com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207) com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394) com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745)

This is my web.xml file :

<servlet>
    <servlet-name>Jersey Web Application</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.rest.example
    </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

And my pom.xml

<dependencies>
<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>asm.jar</artifactId>
    <version>20041228.180559</version>
</dependency>
<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>jersey-bundle.jar</artifactId>
    <version>1.19</version>
</dependency>
<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>jersey-server.jar</artifactId>
    <version>1.19</version>
</dependency>
<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>jersey-core.jar</artifactId>
    <version>1.8</version>
    <type>pom.lastUpdated</type>
</dependency>

The sum.java file

package com.rest.example;

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

public class sum {
@Path("/hello")

@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayHello() 
{
        return "Hello World";
    }

}

And just in case :

and the project itself

I've tried cleaning and building it again but still no change; What am i missing ? thanks.

like image 552
ohadsas Avatar asked Nov 03 '15 02:11

ohadsas


1 Answers

Error Message:

The ResourceConfig instance does not contain any root resource classes.

<init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>com.rest.example</param-value>
</init-param>

The above tells Jersey to scan the com.rest.example package for classes annotated with @Provider and @Path so that it can register them. The error is telling you that no resource classes registered during application load. Reason:

public class sum {
@Path("/hello")

The @Path annotation should go on top of the class definition, not below. Jersey found no resource classes, because the there is no @Path annotation on the class.

like image 111
Paul Samsotha Avatar answered Oct 13 '22 13:10

Paul Samsotha