1

I am really stuck up at a major situation. I have a class in the maven dependancy and also can be referenced from within the class but on running the server displays ClassNotFoundException.

Thanks in advance

update:

Environment:-

  • Eclipse Juno.
  • Maven M2E plugin
  • Tomcat 7

I created a maven project in eclipse and converted it to a dynamic web project in facet changes - and added the following in the pom.xml and also gave the mvn eclipse:eclipse -Dwtpversion=2.0

 <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.8</version>
        </dependency>

This has downloaded the available jars containing the class com.sun.jersey.spi.container.servlet.ServletContainer

But on running the server - java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

2
  • Please provide more details: the relevant dependency declaration, the referencing code etc. Commented Oct 7, 2013 at 12:13
  • Did you try maven->update project configurations ? Commented Oct 7, 2013 at 13:26

2 Answers 2

1

First I would suggest you use the latest version of Eclipse (now its 4.3 Kepler) as it has m2e plugin built in and has much much better support for Maven. You're no longer have to add Maven Dependency to your project classpath manually.

Try creating a new Maven Project from within Eclipse, then choose maven-archetype-webapp as the archetype. Eclipse will set up everything for you including classpath for Maven depdencies.

Whenever you modify a POM.xml, make sure your classpath are updated, though most of the cases this is done automatically by the m2e plugin. Look at the Markers tab at the lower part of your Eclipse to see if you have such problems, if you see something like "Maven Problem, project configurations are not up to date", right click on your project and Choose Maven->Update Projects.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried this too "Try creating a new Maven Project from within Eclipse, then choose maven-archetype-webapp as the archetype. Eclipse will set up everything for you including classpath for Maven depdencies." and also tried updating maven project. Still no developments. I think if I add the classes in the lib folder, it would work, but I need some other workaround
Its because if I add the jars manually then there is no purpose served for Maven
tip to create "maven-archetype-webapp" is the best adive
0

First, make sure you've added the right dependencies:

I think you also need the "jersey-servlet" artifact

Then, make sure you add Maven dependencies to your Java build path?

If not, try the following:

  1. Open project properties and select Java Build path
  2. click on "Add Library"
  3. Select “Maven Managed Dependencies”

1 Comment

Yes it is added. I think I have gone somewhere wrong in converting maven project to web application project. I created a Maven project, then right click - properties -> project facets -> 'selected' dynamic module version, and also gave mvn eclipse:eclipse -Dwtpversion=2.0 in command line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.