Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent duplicate servlet jar using eclipse+m2eclipse

I'm using Eclipse + Maven + m2eclipse to build and test a web application in Apache Tomcat.

I've configured a Tomcat server inside Eclipse, and configured the deployment assembly for my web app, including "Maven Dependencies" (specialization of Java Build Path Entries).

When I deploy and start the server, Tomcat/Catalina always warns me:

INFO: validateJarFile(/projects/src/main/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/webapp/WEB-INF/lib/servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

This is because m2eclipse sees servlet-api-2.5 as a dependency of my project, and considers it as part of "Maven Dependencies", and copies it as part of the deployment assembly, but the Tomcat servlet container has its own copy of this and doesn't like seeing 2 copies on the class path.

I've marked the dependency from my project to servlet-api-2.5 in my pom.xml with

<scope>
provided
</scope>

which does prevent standalone Maven from packaging servlet-api-2.5 into my builds, but m2eclipse doesn't see it that way.

(This isn't a huge deal because the warning is harmless, I only see it during testing inside the IDE, and real customers won't see it, but I'd still like to know how to fix it because I like cleanliness and I like knowing how things work.)

Is there a correct way to tell m2eclipse not to deploy this file, or to tell Eclipse not to let m2eclipse have the final say on which dependencies are runtime dependencies?

I did find https://issues.sonatype.org/browse/MNGECLIPSE-1193 which mentions

the "Maven Dependencies" container reflects test compile time scope, so it is supposed to have dependencies with scope "provided"

like image 403
metamatt Avatar asked May 06 '11 00:05

metamatt


1 Answers

Install extras for m2eclipse plugin ("Maven Integration for WTP") from update site http://m2eclipse.sonatype.org/sites/m2e-extras. After install, update the project configuration.

like image 172
nullpointer forever Avatar answered Oct 16 '22 23:10

nullpointer forever