Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven dependencies not visible in WEB-INF/lib

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 ::(

like image 457
Suraj Chandran Avatar asked May 21 '11 18:05

Suraj Chandran


People also ask

Why Maven dependencies are not getting downloaded?

Maven uses HTTP to download its dependencies along with the dependencies of the Maven project (such as Camel). If you run Maven and it fails to download your required dependencies it's likely to be caused by your local firewall & HTTP proxy configurations.


2 Answers

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.
like image 83
Bozho Avatar answered Oct 06 '22 01:10

Bozho


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.

like image 32
Vedran Avatar answered Oct 05 '22 23:10

Vedran