users@jersey.java.net

[Jersey] Re: Tomcat can't load com.sun.jersey.spi.container.servlet.ServletContainer, but Glasfish can

From: Glen Mazza <gmazza_at_talend.com>
Date: Tue, 14 Feb 2012 09:04:19 -0500

Hi, for an example of how to deploy the Jersey servlet to Tomcat:

For Jersey's "simple servlet" example:
http://java.net/projects/jersey/sources/svn/show/trunk/jersey/samples/simple-servlet?rev=4816

If you set up your Tomcat security configuration as given here:
http://www.jroller.com/gmazza/entry/web_service_tutorial#maventomcat

And add the following plugin config to the pom.xml:

          <plugin>
             <groupId>org.codehaus.mojo</groupId>
             <artifactId>tomcat-maven-plugin</artifactId>
             <version>1.1</version>
             <configuration>
                <server>myTomcat</server>
                <url>http://localhost:8080/manager/text</url>
                <path>/${project.build.finalName}</path>
             </configuration>
          </plugin>

(Use URL|http://localhost:8080/manager above if using Tomcat 6 instead of 7).

Then from a command line window, run "mvn clean install" from the simple servlet directory, followed by "mvn tomcat:deploy" (start up tomcat first!)
you'll see the WAR deployed to Tomcat using this URL:

http://localhost:8080/SimpleServlet/

Note the HTML instructions that come with this Jersy sample say the URL should be:
||http://localhost:8080/SimpleServlet/resources/start
|

But I can't get that particular URL string to work, that might be an
error in the HTML instructions.

HTH,
Glen


On 02/14/2012 07:24 AM, Sven Strittmatter wrote:
> Hello List,
>
> I'm trying to write a simple webapp which serves static files (css/js
> etc.), JSPs, Servlets and especially Jersey resources using Netbeans
> and Maven. The purpose is to learn about Javas web tier. I also want
> to deploy the webapp to different containers. In my case Glassfish,
> Tomcat and Jetty. Also for learning. I realized during my experiments
> that it does not matter in which servlet container a webapp runs.
> Always the same stuff in web.xml and same directory structure.
>
> Everything works fine for me when I deploy the webapp to Glassfish. I
> use that one bundled with Netbeans. But when I deploy to Tomcat (also
> bundled with Netbeans) it complains that it is not possible to load
> the class "com.sun.jersey.spi.container.servlet.ServletContainerm"
> which I reference in the web.xml for Jersey. I do not put any jar
> files into WEB-INF/lib, because I found out that Maven will do this
> for me. And yes, when I inspect the generated war with jar -tf there
> are all Jersey jars (-core, -server, -json, -client) and a lot of
> others in the WEB-INF/lib.
>
> I tried to find com.sun.jersey.spi.container.servlet.ServletContainerm
> in one of my Jersey dependenies[1], but I can't find. So I guess that
> this special class is not in one of the artefacts I depend on. And I
> guess that Glassfish has this class and other components somewhere
> built in. When I download the Jersey bundled jar and put it by hand
> into WEB-INF/lib/ then Tomcat can load the class and everything is
> fine. But I don't want to do that by hand, because Maven should manage
> this.
>
> I'm searching the web for a solution since some days and can't find
> one. May someone help me and point out what I'm doing wrong? I'm not
> sure if it is a problem with my Maven config or with Tomcat.
>
> The whole source code is on GitHub[2]
>
> [1] https://github.com/Weltraumschaf/Citer/blob/master/pom.xml
> [2] https://github.com/Weltraumschaf/Citer
>
> Kind regards
> Sven
>


-- 
Glen Mazza
Talend Community Coders - coders.talend.com
blog: www.jroller.com/gmazza