File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes [Maven] Configuring libs for WARs inside EARs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "[Maven] Configuring libs for WARs inside EARs" Watch "[Maven] Configuring libs for WARs inside EARs" New topic
Author

[Maven] Configuring libs for WARs inside EARs

Ryan Kade
Ranch Hand

Joined: Aug 16, 2005
Posts: 69
I'm migrating our build process from Ant 1.7.0 to Maven 2.0.6, and I've got a whole series of JARs that I've written POMs for, most of which reside inside one of two WARs, which in turn live inside a single EAR.

Some of the projects inside the two WARs share libraries, and so I don't want to have those libraries duplicated in the WAR WEB-INF/lib directories, but rather include them in the EAR and make a reference to them in the WAR manifest. Maven doesn't support this directly, but they do have a workaround as described here:

Creating Skinny WARs

I don't like this solution, since it requires me to specify by name the libraries I want to exclude (using the warSourceExcludes parameter of the maven-war-plugin), which sort of breaks Maven's flexibility, no? Now I have to specify filenames that I'd rather have Maven construct based on my groupId-artifactId-version.

So I concocted an alternative solution. All my POMs for this particular project (JARs, WARs, EAR) inherit from one "master" POM (not the Super POM). I have a huge DependencyManagement section which specifies all the libraries any of the sub-projects would need, along with preferred versions.

When I run across a library that I need to be in the EAR and not in a WAR's WEB-INF/lib, I set it's scope to "provided" in the master POM. Then, in the Dependency section of the EAR, I override it to "compile." For example:



I still have to add the libraries to the manifest--no getting out of that--but then I don't have to specifically exclude them.

In this way, my WAR has no problem compiling, but still looks to the EAR for those joint dependencies.

My question: is this a bad way to do this? Am I hijacking the purpose of the "provided" scope and potentially introducing problems for myself down the road?

What do y'all think?
Ryan Kade
Ranch Hand

Joined: Aug 16, 2005
Posts: 69
After further research, I decided to do this in the reverse. Rather than setting the scope of all the libraries needed by my WARs (yet located in the EAR) to "provided" in the master POM, I do it in each individual WAR file. This functions as an effective exclusion (for transitive dependencies), while still allowing the dependency to be declared in both the WAR and the EAR.

This strikes me as more consistent with the use of the provided scope.

Example:



[ June 27, 2007: Message edited by: Ryan Kade ]
[ June 27, 2007: Message edited by: Ryan Kade ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Maven] Configuring libs for WARs inside EARs
 
Similar Threads
Richfaces + Spring + Maven Setup help
Maven web project dependencies
maven release build error
Ear Building in Maven
Maven dependencies