简体   繁体   中英

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.

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>

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM