users@jersey.java.net

[Jersey] jersey issue with bootstrap jetty

From: Fahad Najib <FNajib_at_xceed.com.sa>
Date: Sun, 10 Mar 2013 08:28:38 +0000

Dear All,
I am trying to bootstrap a simple HelloWorld jersey with jetty.

This is my bootstrap code, I am using intellij and my output goes into target->classes-> :

public class JerseyBootStrapper {
    public static void main(String[] args) throws Exception
    {
        Server server = new Server(8080);
        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
        context.setContextPath("/services");
        context.setInitParameter("com.sun.jersey.config.property.packages",
                "sa.com.xceed.misbar.services.impl.jersey");
        context.addServlet(new ServletHolder(
                new com.sun.jersey.spi.container.servlet.ServletContainer()),"/*");


        server.setHandler(context);
        server.start();
        server.join();
    }
}

My service class is under service/impl/jersey package:
@Path("/hello")
public class HelloWorldService {

    public Response getMsg(@PathParam("param")String msg){
        String output = "Jersey say : " + msg;

        return Response.status(200).entity(output).build();
    }
}



However I face the following error:


2013-03-10 11:21:33.398 [INFO] org.eclipse.jetty.util.log:55 - jetty-7.4.5.v20110725
2013-03-10 11:21:33.435 [INFO] org.eclipse.jetty.util.log:55 - started o.e.j.s.ServletContextHandler{/services/impl/jersey,null}
Mar 10, 2013 11:21:33 AM com.sun.jersey.api.core.WebAppResourceConfig init
INFO: Scanning for root resource and provider classes in the Web app resource paths:
  /WEB-INF/lib
  /WEB-INF/classes
Mar 10, 2013 11:21:33 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
Mar 10, 2013 11:21:33 AM com.sun.jersey.server.impl.application.RootResourceUriRules <init>
SEVERE: The ResourceConfig instance does not contain any root resource classes.
2013-03-10 11:21:33.825 [WARN] /services/impl/jersey:50 - unavailable
com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
                at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99) ~[jersey-server-1.8.jar:1.8]
                at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1298) ~[jersey-server-1.8.jar:1.8]
                at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169) ~[jersey-server-1.8.jar:1.8]
                at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775) ~[jersey-server-1.8.jar:1.8]
                at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771) ~[jersey-server-1.8.jar:1.8]
                at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193) ~[jersey-core-1.8.jar:1.8]
                at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771) ~[jersey-server-1.8.jar:1.8]
                at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766) ~[jersey-server-1.8.jar:1.8]
                at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488) ~[jersey-server-1.8.jar:1.8]
                at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318) ~[jersey-server-1.8.jar:1.8]
                at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609) ~[jersey-server-1.8.jar:1.8]
                at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210) ~[jersey-server-1.8.jar:1.8]
                at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373) ~[jersey-server-1.8.jar:1.8]
                at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556) ~[jersey-server-1.8.jar:1.8]
                at javax.servlet.GenericServlet.init(GenericServlet.java:241) ~[servlet-api-2.5.jar:2.5]
                at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:436) [jetty-servlet-7.4.5.v20110725.jar:7.4.5.v20110725]
                at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:260) [jetty-servlet-7.4.5.v20110725.jar:7.4.5.v20110725]
                at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58) [jetty-util-7.4.5.v20110725.jar:7.4.5.v20110725]
                at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:765) [jetty-servlet-7.4.5.v20110725.jar:7.4.5.v20110725]
                at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:245) [jetty-servlet-7.4.5.v20110725.jar:7.4.5.v20110725]
                at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:586) [jetty-server-7.4.5.v20110725.jar:7.4.5.v20110725]
                at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58) [jetty-util-7.4.5.v20110725.jar:7.4.5.v20110725]
                at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89) [jetty-server-7.4.5.v20110725.jar:7.4.5.v20110725]
                at org.eclipse.jetty.server.Server.doStart(Server.java:258) [jetty-server-7.4.5.v20110725.jar:7.4.5.v20110725]
                at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58) [jetty-util-7.4.5.v20110725.jar:7.4.5.v20110725]
                at sa.com.xceed.misbar.services.framework.runner.JerseyBootStrapper.main(JerseyBootStrapper.java:27) [classes/:na]
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_41]
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_41]
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_41]
                at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_41]
                at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) [idea_rt.jar:na]
2013-03-10 11:21:33.852 [INFO] org.eclipse.jetty.util.log:55 - Started SelectChannelConnector_at_0.0.0.0:8080 STARTING



Best regards,
Fahad najib