Hi Guys i am new to maven and webapps, so please bear with me. I have gone through most of the solutions in stack overflow like java.lang.ClassNotFoundException: com.sun.jersey
So a couple things. First the problem with the ClassNotFoundExcetion
. The class is in the jersey-servlet
jar. Looking inside the built .war
file all the jars are build to the war. So if you deployed the war manually it should work.
This is a problem I see a lot with Eclipse users. I don't know if you are using Eclipse, what I have come to figure out is that, in the problem cases, Eclipse doesn't deploy the actual war to the server but creates an internal instance of the server and deploys the project artifacts instead of the actual war. In which case it doesn't load the jars.
As a sanity check, you can add this jetty-maven-plugin
. I use it all the time for development
org.eclipse.jetty
jetty-maven-plugin
9.2.6.v20141205
...
Then from the command line, you can run mvn jetty:run
. This will deploy your app to an embedded Jetty instance created by Maven. I tested with your project it and works fine.
The second thing is the dependencies. You need to decide what version of Jersey you want to user, a 1.x
version or a 2.x
version. Which ever you choose, you should get rid of all the other version artifacts.
For your current project, assuming you wan to use Jersey 1.x, you should get rid of these two in your current project.
org.glassfish.jersey.containers
jersey-container-servlet
2.0
org.glassfish.jersey.core
jersey-client
2.0
Removing those two and running with the Jetty plugin should work fine. As far as trying to run it from the IDE, I am not sure how to solve that problem.