aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes How to include maven dependencies in war file (WEB-INF/lib) deployed using m2eclipse plugin Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "How to include maven dependencies in war file (WEB-INF/lib) deployed using m2eclipse plugin" Watch "How to include maven dependencies in war file (WEB-INF/lib) deployed using m2eclipse plugin" New topic
Author

How to include maven dependencies in war file (WEB-INF/lib) deployed using m2eclipse plugin

Benjamin Weaver
Ranch Hand

Joined: Apr 08, 2003
Posts: 161
I am new to using the m2eclipse plugin. I am using eclipse Helios 3.6.2. java: 1.6.0.31

I want to include various maven dependencies (.jar files) in my .war depolyment. I want these jars to end up in the war file under myApp/WEB-INF/lib.

Currently I can build the project using the traditional eclipse method: from the Tomcat option | Deploy to war file path. Eclipse is apparently building against my .m2 repository. But presently only my project classes are exported to the war.


1. By what steps do I select the maven dependencies in eclipse for export to WEB-INF/lib ?

2. Once these are set up, how can I run a maven command to build the war file from within eclipse that will export the dependencies? Should I run the command using maven or can I do it in eclipse?


For example, in a simple JDBC application connecting to say oracle, let's say I want to include the jta-1.0.1.jar in under WEB-INF/lib on deployment. I have an entry in my pom file for it, as a dependency. jta-1.0.1.jar needs to end up under myApp/WEB-INF/lib/.

Many thanks in advance!

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16070
    
  21

Just ensure that your POM is set up to generate a WAR (and not something such as JAR, instead).

Dependencies in "compile" scope will automatically be copied to the target's WEB-INF/lib as part of the Maven build. Dependencies in "provided" scope will not (you would use this for server-supplied jars such as the JSP-api.jar).


To generate a WAR in Maven, 2 goals have to be run: "compile" and "war:war". Running the war goal alone won't compile the Java source . If you prefer, run one of the master goals, such as "package".

To run Maven in Eclipse, select the POM in the project explorer and select the "Run" context menu option. This will build and execute Maven run profile (or use an existing one). Maven run profiles behave just like regular run/debug profiles except that their profile edit dialogs support Maven-specific features.

Customer surveys are for companies who didn't pay proper attention to begin with.
Benjamin Weaver
Ranch Hand

Joined: Apr 08, 2003
Posts: 161
Thank you very much Tim, this was an extremely helpful answer.
This helped loads

I also found a good web page for this:
http://www.mkyong.com/maven/how-do-use-maven-to-create-a-dynamic-web-project-in-eclipse/


One thing I notice I am still getting is this file, called 'maven' which is deposited in my META-INF directory. I delete it after expanding the war, but I'll admit it's annoying.

Thanks for the help.

Ben
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5830
    
    7

To get rid of the maven directory under META-INF, set addMavenDescriptor to false for the war plugin:



It is often worthwhile to examine the available configuration options on various plugins:
For the war:war mojo: http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html
For the <archive> config item: http://maven.apache.org/shared/maven-archiver/index.html (these apply to WAR and JAR...)

By the way, if you would have followed the maven directory and its subdirectories you would have eventually reached a copy of you pom.xml. Sometimes this is handy (especially when you examine a JAR file that you got from someone else) and sometimes it's not so handy (if you are writing proprietary software and you have the developer's email addresses in the <developers> section of the POM - you really want your customers to contact support, and not the developers directly).


JBoss In Action
Benjamin Weaver
Ranch Hand

Joined: Apr 08, 2003
Posts: 161
Thanks, Peter: perfect, did the trick.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to include maven dependencies in war file (WEB-INF/lib) deployed using m2eclipse plugin