Waqas Ali
Waqas Ali

Reputation: 1652

Tomcat Start up error in Restful web service using Jersey

I got tomcat startup exception this

SEVERE: Servlet /WebServiceModule threw load() exception
java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

After getting exception tomcat startup and work fine but it doesn't work as expected.

I have included the following jersey and its dependency in the java build path

jersey-bundle-1.17
jaxb-imp-2.2.4
jaxb-api-2.2.9
asm-3.1

In jersey bundle library com.sun.jersey.spi.container.servlet package exists and it have ServletContainer.class file. I am using tomcat 7.0 server and all of the work is doing in eclipse.

Upvotes: 0

Views: 2210

Answers (3)

1218985
1218985

Reputation: 8032

The com.sun.jersey.spi.container.servlet.ServletContainer is included in jersey-server.jar, not jersey-core.jar. To develop REST service with Jersey, you just need to include jersey-server.jar, and it will download the jersey-core.jar dependency automatically. Only add the dependency in pom.xml as shown below:

<dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-server</artifactId>
   <version>1.8</version>
</dependency>

Now your application will have the class com.sun.jersey.spi.container.servlet.ServletContainer

Upvotes: 0

user1930502
user1930502

Reputation:

Which building tool do you use ? Maven ? Build by means of IDE ? Make sure that all libraries are deploayed with/inside your War ! Everytime I got this exception, adding the missing library into War file solved the problem.

If you build with your IDE, you most certainly need to tell it first which packages will be included in your deployed WAR.

Upvotes: 0

Juned Ahsan
Juned Ahsan

Reputation: 68715

The “com.sun.jersey.spi.container.servlet.ServletContainer” is included in “jersey-server.jar“. Make sure you have it in your dependency path. If you are using maven then use this:

<dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.8</version>
    </dependency>

Upvotes: 1

Related Questions