I\'m trying to make a REST web service.
My project looks like :
<I have encountered the same issue. I was using Version 1.12.
I could not find the class com.sun.jersey.spi.container.servlet.ServletContainer
in the "jersey-server-1.12.jar" or "jersey-core-1.12.jar" as suggested in some other forums.
You can easily check this in Eclipse, when you add it to the Build Path and notice that you do not have that class in the above mentioned jar files.
I searched around and found the following:
It looks like the class com.sun.jersey.spi.container.servlet.ServletContainer
is in a different jar file ("jersey-servlet-1.12.jar").
I did not find any documentation about this. However having this file in my WEB-INF/lib resolved this issue.
Hope this helps.
luigi7up's post above worked for me. I'm using tomcat 7.0.37, maven 3.1.1, and jersey 1.17.1. I did the right click -> properties -> Deployment Assembly -> Click Add -> Java Build Path Entries -> selected Maven Dependencies. I then clicked ok.
When I first tried this, I noticed that I no longer received the "java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer" error, but I then noticed that I was getting other 'class not found' messages (unfortunately, I didn't document what messages those were). I was using the following jersey dependency:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.17.1</version>
</dependency>
I took that out and put in the following dependencies:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.17.1</version>
</dependency>
Things began to work after that.
Hope this helps someone!
Solution:
Only add the dependency in pom.xml:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.13</version>
</dependency>
Now your application will have the class com.sun.jersey.spi.container.servlet.ServletContainer
ps: Remember to check if the libraries are being sent to the tomcat deploy.
To check:
Right-click on your project -> Properties -> Deployment Assembler and make sure the Source tab contains Maven Dependecies.
Otherwise:
Click on button Add -> Java Build Path -> Maven Dependecies -> Finish.
Ready whenever you run the application all the libs will be imported in the deploy.
ps: Where the Maven project is updated, you must remake these steps.
If you're working with Maven then the possible issue might be that your jars don't get deployed to your Tomcat. So, you have your Maven Dependencies in the Java Build Path (Project > Properties > Build path), but when running the project on your Tomcat from Eclipse Maven Dependencies don't get deployed to TOmcat. To solve this you have to: right click > properties and select "Deployment Assembly". And add Java Build Path Entries. This way you're telling the WTP plugin (the one running Tomcat within Eclipse) that it should also copy the Maven's jars
I added it to the WEB-INF/lib
directory but it did not work until I refreshed the lib folder from Eclipse and then it started working.
Anjaneya Reddy, as you've pointed out, the class isn't even in the JAR it's supposed to be in. What baffles me, where is it and where in the documentation does it touch on this?!?
With everything being so Maven friendly now, it's difficult to bang out a simple tutorial without needing to depend on it.