創建coffee-parent項目
New->Maven Project
創建coffee-web項目
右鍵coffee-parent項目->New->Project...
注意:需要在src/main/webapp下創建WEB-INF文件夾,以及在WEB-INF下創建web.xml。
創建coffee-api項目
右鍵coffee-parent項目->New->Project...
注意:前面步驟同coffee-web項目
項目結構:
pom.xml文件
coffee-parent項目的pom.xml:
<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.coffee</groupId>
<artifactId>coffee-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>coffee-web</module>
<module>coffee-api</module>
</modules>
<!-- 管理依賴,供子項目選擇使用 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.coffee</groupId>
<artifactId>coffee-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<!-- 配置使用jdk1.7編譯,所有子項目都會繼承此配置,如需配置為子項目可選繼承,則需要配置到 pluginManagement下-->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
coffee-web項目的pom.xml:
<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>com.coffee</groupId>
<artifactId>coffee-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>coffee-web</artifactId>
<packaging>war</packaging>
<!-- coffee-web依賴coffee-api,無需配置version,使用父項目coffee-parent中配置的version-->
<dependencies>
<dependency>
<groupId>com.coffee</groupId>
<artifactId>coffee-api</artifactId>
</dependency>
</dependencies>
</project>
coffee-api項目的pom.xml:
<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>com.coffee</groupId>
<artifactId>coffee-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>coffee-api</artifactId>
</project>
構建
右鍵coffee-parent項目->Run As->Maven install
構建成功:
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for coffee-parent 0.0.1-SNAPSHOT:
[INFO]
[INFO] coffee-parent ...................................... SUCCESS [ 0.754 s]
[INFO] coffee-api ......................................... SUCCESS [ 2.085 s]
[INFO] coffee-web ......................................... SUCCESS [ 0.888 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.980 s
[INFO] Finished at: 2019-06-03T21:44:43+08:00
[INFO] ------------------------------------------------------------------------