It's already been answered in the comments but here's an example.
A parent pom:
<?xml version="1.0" encoding="UTF-8"?> <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>com.essexboy</groupId> <artifactId>parent</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>jar1</module> <module>jar2</module> </modules> </project>
And 2 child/modules poms, only the artifactId is different:
<?xml version="1.0" encoding="UTF-8"?> <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> <artifactId>parent</artifactId> <groupId>com.essexboy</groupId> <version>1.0-SNAPSHOT</version> </parent> <artifactId>jar1</artifactId> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies> <build> </build> </project>
Extra info
I created the parent with the command:
mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=pom-root -DarchetypeVersion=RELEASE
Then created 2 modules with the command
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=RELEASE
If you must have a single jar project (no modules and parent) you can do it with the shade-plugin:
<?xml version="1.0" encoding="UTF-8"?> <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>com.essexboy</groupId> <artifactId>double-jar</artifactId> <version>1.0-SNAPSHOT</version> <name>double-jar</name> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.2.1</version> <executions> <execution> <id>1</id> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <finalName>jar1</finalName> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>com/essexboy/App2*</exclude> </excludes> </filter> </filters> </configuration> </execution> <execution> <id>2</id> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <finalName>jar2</finalName> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>com/essexboy/App1*</exclude> </excludes> </filter> </filters> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>