I have a multi-module Apache Maven 3.3.3 project with n*** (multiple) module projects:
/mvnModular
/modules
/modules /mainApp /pom.xml
/modules /module1 /pom.xml
/modules /module2 /pom.xml
/modules /moduleChat /pom.xml
/modules /moduleBlog /pom.xml
...
modules has only one file, pom.xml:
<groupId>mainmod.modules</groupId>
<artifactId>modules</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>..\mainApp\pom.xml</module>
<module>..\module1\pom.xml</module>
<module>..\module2\pom.xml</module>
<module>..\moduleChat\pom.xml</module>
<module>..\moduleBlog\pom.xml</module>
</modules>
...
How can I go about adding all the .jar files from the individual modules projects into a folder, called lib, in the project root folder, mvnModular?
This is what I would like at the end:
/mvnModular
mainApp.jar
/lib
/lib /module1.jar
/lib /module2.jar
/lib /moduleChat.jar
/lib /moduleBlog.jar
.....
The individual modules have a pom.xml file like this one:
<parent>
<groupId>mainmod.modules</groupId>
<artifactId>modules</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../modules/pom.xml</relativePath>
</parent>
<groupId>mainmod.modules.module2</groupId>
<artifactId>module2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>module1</name>
UPDATE
The idea is to have an application written in a way that a user will download the project mainApp
that contains mainApp.jar in the root mvnModular folder innitially, which is the main project. Then the application (mainApp.jar) could be extended by adding modules to a folder called packages in the mvnModular root.
You can use maven-antrun-plugin for that. This will have to be added to every module.
Check the sample below.
parent POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TestMavenModules</groupId>
<artifactId>TestMavenModules</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>Module1</module>
<module>Module2</module>
</modules>
</project>
Module1 POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>TestMavenModules</groupId>
<artifactId>TestMavenModules</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>Module</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<copy
file="${project.build.directory}/${project.artifactId}-${project.version}.jar"
todir="../PackagedJars" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Module2 POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>TestMavenModules</groupId>
<artifactId>TestMavenModules</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>Module2</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<copy
file="${project.build.directory}/${project.artifactId}-${project.version}.jar"
todir="../PackagedJars" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Finally you'll have jars in PackagedJars directory in the root.
/PackagedJars
----/Module1-0.0.1-SNAPSHOT.jar
----/Module2-0.0.1-SNAPSHOT.jar
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.