aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Maven - Compile dependency on Jar(s) inside EAR 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 - Compile dependency on Jar(s) inside EAR" Watch "Maven - Compile dependency on Jar(s) inside EAR" New topic
Author

Maven - Compile dependency on Jar(s) inside EAR

Anish Pyne
Greenhorn

Joined: Aug 23, 2010
Posts: 15
I have following structure of projects -

a. EAR A --> Contains a bunch of 3rd party libs in APP-INF/lib E.g. log4j, axis, etc
b. WAR B --> Has some classes which need say log4j to compile
c. WAR C --> Has some classes which need say log4, as well as axis to compile

I want the POMs of WAR B & WAR C to use the libs inside EAR A to compile. I do not intend to package the dependency jars into the generated EARs for B & C.

Finally on server EAR A would be deployed as a shared library for WAR B & WAR C.

How to achieve this?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5778
    
    7

You need to read about using dependency scope in Maven:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

Basically, you want to set the scope of log4j to 'provided' for both 'b' and 'c', and to 'compile' for 'a'


JBoss In Action
Anish Pyne
Greenhorn

Joined: Aug 23, 2010
Posts: 15
Peter, thanks for the link.

I am trying to simulate the shared library concept of Weblogic basically. At the time of building my war files B & C I want the compilation to run fine by referencing the jars/dependencies already specified inside EAR.

Based on the article, looks like adding EAR A as dependency with "import" scope to the POMs of WAR B & WAR C should do the job. Please correct me if I am wrong.

However at the time of packaging WAR B & WAR C I don't want the dependency jars to get packaged as part of the WAR file. I guess I can achieve that by using some exclusion filters.

Please share your thoughts on this.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

EARs are not "shared libraries", whether you use Maven to build or not.

An EAR is a deployable J2EE web component. As part of the deployment process, the EAR is installed in the appserver in its own unique classpath, which cannot be accessed via the classpaths of any other WARs or EARs in that server, and vice versa (since they, too have their own unique classpaths).

You can build library JARs as Maven components and make them dependencies for both WARs and EARs, but in any event, an EAR couldn't serve as a classpath library because the actual classes inside the EAR aren't located where the appserver's classloader will find them.


Customer surveys are for companies who didn't pay proper attention to begin with.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5778
    
    7

I want the compilation to run fine by referencing the jars/dependencies already specified inside EAR.

That is not how Maven works. Maven stores each artifact (JAR, WAR, EAR) separately, and you need to refer directly to your artifacts.

And as Tim pointed out, using an EAR as a dependency won't work because it is not a valid classpath item - there is no visibility to the JAR or WAR files it contains.
Anish Pyne
Greenhorn

Joined: Aug 23, 2010
Posts: 15
@Peter, @Tim - Both of you are totally correct in what you are saying and I am aware of that. However I am getting introduced to Weblogic for first time at my new workplace and I come across this concept of shared libraries in Weblogic where a war can have a dependency on another war's included libs. It looked weird to me as well when I first saw it. My intention was to replace regular Weblogic workshop builds (using shared libraries) with Maven equivalent.

Did some research and it turns out that what Weblogic internally is extract out the contents internally and add to classpath(at a very high level).

Anyways I have been able to achieve what I wanted using the Maven Warpath plugin. So of posting it so that others looking to achieve the same can find it easily.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

I'm not sure I'd be comfortable with that. The risks appear to outweigh the benefits.

Actually, from what I can see, it's not a WebLogic thing, it's an AppFuse thing, and I'd thought better of them than that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Maven - Compile dependency on Jar(s) inside EAR
 
Similar Threads
log4j.properties file outside application
new bee weblogic classloading
how to share web resources(html,jsp,classes in WEB-INF/classes) ascoss wars in a single ear
[Maven] Configuring libs for WARs inside EARs
maven: the war directory structure