I just started learning Jersey, but found the Jersey's sample code
configurations are too tightly tied to the Jersey-Samples parent
project for beginner to do a standalone package for tomcat. I
struggled quite a bit until I found this link
http://www.mkyong.com/webservices/jax-rs/jersey-hello-world-example/
which is much more straight-forward on how to package a WAR for
tomcat. Hopefully it will help you troubleshooting.
-- Jim.
On Wed, Feb 8, 2012 at 11:39 AM, Glen Mazza <gmazza_at_talend.com> wrote:
> I would first try to run Jersey's bare-bones helloworld-webapp sample on
> Tomcat to see if that works (to rule out Tomcat being the problem), then try
> to determine why it is not working for your particular WAR.
>
> Glen
>
>
> On 02/08/2012 10:23 AM, dinesh gaglani wrote:
>
> Hi,
>
> I was able to run my jersey application on JBoss-4.2.3,
>
> 2012-02-08 07:17:19,169 Feb 8, 2012 7:17:19 AM
> com.sun.jersey.api.core.ScanningResourceConfig logClasses
> INFO: Root resource classes found:
> class com.intruvert.restapi.resource.SensorsResource
> class com.intruvert.restapi.resource.HeartbeatResource
> class com.intruvert.restapi.resource.SensorResource
> class com.intruvert.restapi.resource.AttackFiltersResource
> class com.intruvert.restapi.resource.DomainResource
> class com.intruvert.restapi.resource.InterfaceResource
> class com.intruvert.restapi.resource.AttackFilterResource
> class com.intruvert.restapi.resource.SessionResource
> 2012-02-08 07:17:19,185 Feb 8, 2012 7:17:19 AM
> com.sun.jersey.api.core.ScanningResourceConfig logClasses
> INFO: Provider classes found:
> class com.intruvert.restapi.app.jersey.CustomExceptionMapper
> class com.intruvert.restapi.app.jersey.InjectableProviderImpl
> 2012-02-08 07:17:19,825 Feb 8, 2012 7:17:19 AM
> com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
> INFO: Initiating Jersey application, version 'Jersey: 1.9.1 09/14/2011 02:05
> PM'
> 2012-02-08 07:17:20,997 Feb 8, 2012 7:17:20 AM
> com.sun.jersey.api.wadl.config.WadlGeneratorLoader loadWadlGenerator
> INFO: Loading wadlGenerator
> com.sun.jersey.server.wadl.generators.WadlGeneratorJAXBGrammarGenerator
>
>
>
> but on running in apache-tomcat-6.0.35 I got the following error
>
>
> INFO: Scanning for root resource and provider classes in the packages:
> com.intruvert.restapi.resource
> com.intruvert.restapi.app.jersey
> Feb 8, 2012 6:49:28 AM
> com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
> INFO: Initiating Jersey application, version 'Jersey: 1.9.1 09/14/2011 02:05
> PM'
> Feb 8, 2012 6:49:29 AM
> com.sun.jersey.server.impl.application.RootResourceUriRules <init>
> SEVERE: The ResourceConfig instance does not contain any root resource
> classes.
> Feb 8, 2012 6:49:29 AM org.apache.catalina.core.ApplicationContext log
> SEVERE: StandardWrapper.Throwable
> 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)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1298)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)
> at
> com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
> at
> com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
> at
> com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318
> )
> at
> com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
> at
> com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
> at
> com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
> at
> com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
> at javax.servlet.GenericServlet.init(GenericServlet.java:212)
> at
> org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1206)
> at
> org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
> at
> org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
> at
> org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
> at
> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
> at
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
> at
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
> at
> org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
> at
> org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
> at
> org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
> at
> org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
> at
> org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
> at
> org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
> at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
> at
> org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
> at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
> at
> org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
> at
> org.apache.catalina.core.StandardService.start(StandardService.java:525)
> at
> org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
> at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
> at
> com.intruvert.common.utility.startup.StartupChecks.main(StartupChecks.java:121)
> Feb 8, 2012 6:49:29 AM org.apache.catalina.core.StandardContext
> loadOnStartup
> SEVERE: Servlet /restapi.war threw load() exception
> 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)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1298)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)
> at
> com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
> at
> com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
> at
> com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318
> )
> at
> com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
> at
> com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
> at
> com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
> at
> com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
> at javax.servlet.GenericServlet.init(GenericServlet.java:212)
> at
> org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1206)
> at
> org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
> at
> org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
> at
> org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
> at
> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
> at
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
> at
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
> at
> org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
> at
> org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
> at
> org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
> at
> org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
> at
> org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
> at
> org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
> at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
> at
> org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
> at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
> at
> org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
> at
> org.apache.catalina.core.StandardService.start(StandardService.java:525)
> at
> org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
> at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
> at
> com.intruvert.common.utility.startup.StartupChecks.main(StartupChecks.java:121).
>
> I am using the same web.xml in both the containers
>
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app id="WebApp_ID" version="2.4"
> xmlns="http://java.sun.com/xml/ns/j2ee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
> <display-name>RestApi</display-name>
>
> <servlet>
> <servlet-name>JerseyServlet</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.intruvert.restapi.resource;com.intruvert.restapi.app.jersey</param-value>
> </init-param>
> <init-param>
>
> <param-name>com.sun.jersey.config.property.WadlGeneratorConfig</param-name>
>
> <param-value>com.intruvert.restapi.app.jersey.SchemaGenConfig</param-value>
> </init-param>
> <load-on-startup>1</load-on-startup>
> </servlet>
>
> <servlet-mapping>
> <servlet-name>JerseyServlet</servlet-name>
> <url-pattern>/*</url-pattern>
> </servlet-mapping>
> </web-app>
>
> Here is one of the resource classes
>
> package com.intruvert.restapi.resource;
>
> import java.util.Arrays;
>
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.Produces;
> import javax.ws.rs.QueryParam;
> import javax.ws.rs.core.Context;
> import javax.ws.rs.core.Response.Status;
>
> import com.intruvert.restapi.app.jersey.IntegerAsString;
> import com.intruvert.restapi.app.jersey.RestAPIConstants;
> import com.intruvert.restapi.data.sensor.GetSensorsResponse;
> import com.intruvert.restapi.helpers.ExceptionHelper;
> import com.intruvert.restapi.helpers.SubscriberResourcesHelper;
>
> @Path("/sensors")
> public class SensorsResource {
>
> @Context
> Boolean isCredentialsValid;
>
> @GET
> @Produces({ RestAPIConstants.oldReturnTypeXmlVersion,
> RestAPIConstants.oldReturnTypeJsonVersion,
> RestAPIConstants.newReturnTypeXmlVersion,
> RestAPIConstants.newReturnTypeJsonVersion })
> public GetSensorsResponse getSensorsForDomain(
> @QueryParam("domain") IntegerAsString domainId) throws
> Exception{
> if (isCredentialsValid) {
> GetSensorsResponse resp = new GetSensorsResponse();
> resp.getSensorDescriptor().addAll(
> Arrays.asList(SubscriberResourcesHelper
> .getSensors(domainId.getIntegerValue())));
> return resp;
> } else {
> // Throw error saying "Session Invalid"
> throw ExceptionHelper.createWebApplicationException(
> ExceptionHelper.INVALID_CREDENTIALS_ERROR,
> Status.UNAUTHORIZED);
> }
>
> }
>
> }
>
> Could someone please point out what I am doing wrong here
>
> Thanks,
> Dinesh
>
>
>
> --
> Glen Mazza
> Talend Community Coders - coders.talend.com
> blog: www.jroller.com/gmazza
--
--------------------------------------
Standing Bear Has Spoken
--------------------------------------