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
There seemed to be a version issue. Just change the asm version used in the pom from 3.3.1 to 3.1 and it works.
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.1</version>
</dependency>
and not
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>
Output of code
So finally i made it work with Jboss. If others are facing this problem and don't want to use jetty (i still use it during development phase). Right click your eclipse project Properties -> Deployment Assembly -> Add -> Java Build Path Entries -> Maven Dependencies -> Finish. Clean install maven build. Copy war file to Jboss standalone deployment folder.
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
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.6.v20141205</version>
</plugin>
...
</plugins>
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.
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.0</version>
</dependency>
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.