user2465039 user2465039 - 3 months ago 7x
Java Question

Jersey 2.0 "Getting Started" guide, mainClass not found

Hi I am trying to follow the Getting Started guide for Jersey 2.0.

I did steps 1.1 and 1.2 as is. No problem there.

For step 1.3 I had a problem cause maven could not find the javax-annotation 1.2 but I solved it following the advice of another Stackoverflow user and added a repository to my pom.


mvn clean test
passes with no problems, BUT when I try to run
mvn clean exec:java
I get back

[WARNING] java.lang.ClassNotFoundException: com.example.Main
at Method)
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at org.codehaus.mojo.exec.ExecJavaMojo$

The pom.xml is the one created by the following command:

mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 \
-DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \
-DgroupId=com.example -DartifactId=simple-service -Dpackage=com.example \

where the only addition I 've made is the following:


In case it is of interest this is the output of
mvn -version

Apache Maven 3.0.4 (r1232337; 2012-01-17 10:44:56+0200)
Maven home: /usr/share/maven
Java version: 1.7.0_21, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/jre
Default locale: el_GR, platform encoding: UTF-8
OS name: "mac os x", version: "10.8.3", arch: "x86_64", family: "mac"


I am able to reproduce your error. This has nothing to do with Jersey; it's an error you're making with Maven. mvn clean exec:java says: "delete all the .class files and then try to run the Main .class file". Since you deleted it, Maven can't find it. Here's a solution:

mvn clean compile exec:java

This should fix the problem in your question. This says "delete all the .class files, recompile them from source and then try to run the Main .class file"

To get past the next error you'll see, delete the <scope>test</scope> line from the client dependency in the pom.xml: