69
votes

I'm having this weird problem making my project Maven-based. I created a new Maven project in Eclipse and enabled the Dynamic Web facets. But during runtime now it throws ClassNotFoundException because the Maven dependencies are not copied to WEB-INF/lib directory. I even tried adding the copy-dependencies section in POM, but it didn't help.

Someone here seemed to have solved this the right way, but I guess he forgot to mention the solution ::(

9
Try the latest m2eclipse plugin. I think there are two parts to it and it helped me with getting the maven dependencies on the eclipse class path.xecaps12
To make maven play nice with wtp, I had to install the core and the extras from here: m2eclipse.sonatype.org/installing-m2eclipse.htmlxecaps12
@xecaps thanks, but i had already done thisSuraj Chandran

9 Answers

174
votes

This should have nothing to do with eclipse and m2eclipse, and optionally for better support - m2e-wtp. Also, you don't need copy-dependencies. Here are a few possible reasons:

  • you should invoke mvn package (or right-click > maven > package) and obtain a war file - the <packaging> (in the pom) must be war
  • your dependencies should be with the default scope (if they are provided or test they will not be included in the archive)
  • if you are running the project as dynamic web project on a server within eclipse, then you should open the project properties (right click > properties) and select "Deployment Assembly". There click "add", select "build path entries", and choose "maven dependencies". This will instruct WTP to send the maven dependencies to the server dir.
12
votes

First install Maven Integration For Eclipse WTP (Help->Eclipse Marketplace)

Then in your web project's pom.xml just add:

    <packaging>war</packaging>

After that just right click the project, Maven -> Update Project, which should automagically add Maven Dependencies for you in the Deployment Assembly.

5
votes

Right-click project > Maven > Update Maven Project > OK fixed it for me

4
votes

Check the Deployment Assembly property of the project. I have seen some mvn eclipse:eclipse generated Eclipse projects sometimes have the assets being deployed to the wrong location. From what I can remember the new Deployment Assembly had some issues with earlier versions of Eclipse 3.6 (Helios).

3
votes

I just did maven -> update project worked for me.

0
votes

you want to use the copy-dependencies plugin

see this post and the docs

0
votes

If you look into your deployment and see that WEB-Inf/lib is empty of your Maven dependencies, then ensuring those Maven dependencies are in your deployment assembly is crucial as mention in the chosen answer.

However be wary of Eclipse then not refreshing everything even with a Maven update. If you clean, rebuild and redeploy and still do not see the lib folder being populated try removing and re-adding the application to the server deployments via Servers>Add and Remove.

This unclogged the system for me.

0
votes

Right-click project -> Deployment Assembly: See if you have the Maven Dependencies and all others in there. If not, Right-Click project -> Maven -> Enable Workspace Resolution

(maybe then Maven -> Update Project, but then look again into "Deployment Assembly" and see what You've got.) this solved it (finally!) for me.

0
votes

On Eclipse, select your Web Project -> right click -> Properties -> Deployment Assembly -> Add -> Java Build Path Entries -> Maven Dependencies

With this steps, maven libraries will be included on WEB-INF/lib when full publish.