• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Maven - Compile dependency on Jar(s) inside EAR

 
Anish Pyne
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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'
 
Anish Pyne
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18281
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Pie
Posts: 18281
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic