您可以爲project1,project2和project3製作單獨的罐子。將project2和project3作爲依賴項添加到project1。將project1作爲父項添加到project2和project3。相應的pom文件可能如下所示。
項目1:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>project1</artifactId>
<name>${project.artifactId}</name>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>project3</module>
<module>project2</module>
</modules>
</project>
Project2的:
<?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>project1</artifactId>
<groupId>com.stackoverflow</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.stackoverflow</groupId>
<artifactId>project2</artifactId>
<name>${project.artifactId}</name>
<url>http://maven.apache.org</url>
</project>
項目3:
<?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>project1</artifactId>
<groupId>com.stackoverflow</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.stackoverflow</groupId>
<artifactId>project2</artifactId>
<name>${project.artifactId}</name>
<url>http://maven.apache.org</url>
</project>
我不知道你爲什麼會想一切到一個罐子下包裝。如果你按照上面的配置,所有東西都會被打包到project1中。這基本上和一切都包裝在一個jar下一樣。