Maven - Exchange libraries between projects

I am working on a multiproject, and now I have a structure that resembles this (actually there are a couple of jar projects and several military projects)

/myProj |_______projA (jar) | |____pom.xml | |____target/jar files |_______projB (war) | |___pom.xml | |___web-inf/lib/jarfiles |_______projEar | |___pom.xml |___pom.xml 

What I want to achieve is to make projA and projB to read their dependencies from a shared public folder instead of saving their own copy.

Actually, I don't care where they read them at compile time, but when I pack my EAR file, I want each jar / war be displayed only once, which reduces the size of the EAR.

I tried declaring dependencies of the parent pom, declaring dependencies like some other things, but so far I have not achieved this.

Is there an easy way to achieve this? Any simple maven plugin?

Thanks in advance.

+4
source share
2 answers

You must do this by adding a JAR depending on your pom.xml EAR:

 <dependencies> <dependency> <groupId>com.mycompany</groupId> <artifactId>myapp-web</artifactId> <version>1.0-SNAPSHOT</version> <type>war</type> </dependency> <dependency> <groupId>com.mycompany</groupId> <artifactId>myapp-utils</artifactId> <version>0.0.1-SNAPSHOT</version> <type>jar</type> </dependency> </dependencies> 

... and specifying the dependency specified in your WARs pom.xml:

  <dependency> <groupId>com.mycompany</groupId> <artifactId>myapp-utils</artifactId> <version>0.0.1-SNAPSHOT</version> <scope>provided</scope> </dependency> 

If Maven / another tool has already copied the JAR to the WEB-INF/lib , you may need to delete the file manually before recovery.

This should result in an EAR form:

 META-INF/MANIFEST.MF lib/myapp-utils-0.0.1-SNAPSHOT.jar META-INF/application.xml myapp-web.war 
+6
source

When you move to Maven, you should not store dependency JARs in the code base. I would suggest you create a central Maven repository that will contain all the dependencies.

Contact mvn install to first install these artifacts in the local repository. Alternatively, you can go to the central maven repository for artifacts when building.

What you need to do: remove the entire jar of dependencies from the source code and all your dependency in pom.xml . They will be downloaded and packaged from the maven central repository as needed. Set the Dependency accordingly in the artifacts.

+3
source

All Articles