Maven 聚合項目建立

第一步:建立父工程web

右擊空白處,new 建立新的 maven 工程apache

 

這裏跳過默認的骨架,使用自動義的骨架maven

 

這裏父工程必須使用pom打包方式ui

 

 

第二步:建立子工程spa

右擊空白處,new建立新maven工程插件

 

跳過默認骨架,輸入子工程名,並引用父工程code

 

定義子工程,這裏是以表現層爲例,是web工程,因此打包方式爲war,若是是其餘非web工程就能夠打包成jar,這一點須要注意。xml

 

其餘工程步驟相似,須要注意的是打包方式的選擇。blog

工程建立完成後現象:io

全部的子工程目錄不是單獨的存在,而是直接保存在父工程目錄下。

 

 

web項目建立完後,會有以下錯誤:

 

解決方案:

若是WebContent/WEB-INF/web.xml文件存在,須要在pom.xml文件的<build>節點中,加上maven-war-plugin插件配置。

 1 <plugins>
 2     <plugin>
 3         <groupId>org.apache.maven.plugins</groupId>
 4         <artifactId>maven-war-plugin</artifactId>
 5         <version>3.0.0</version>
 6         <configuration>
 7             <webResources>
 8                 <resource>
 9                     <directory>WebContent</directory>
10                 </resource>
11             </webResources>
12         </configuration>
13     </plugin>
14 </plugins>

 

若是WebContent/WEB-INF/web.xml文件不存在,則按下面的方式配置。

 1 <plugins>
 2     <plugin>
 3         <groupId>org.apache.maven.plugins</groupId>
 4         <artifactId>maven-war-plugin</artifactId>
 5         <version>3.0.0</version>
 6         <configuration>
 7             <failOnMissingWebXml>false</failOnMissingWebXml>
 8         </configuration>
 9     </plugin>
10 </plugins>

 

web工程完整的pom.xml以下:

 1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 2     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 3     <modelVersion>4.0.0</modelVersion>
 4     <parent>
 5         <groupId>com.maven.manage</groupId>
 6         <artifactId>maven-manage</artifactId>
 7         <version>0.0.1-SNAPSHOT</version>
 8     </parent>
 9     <artifactId>maven-manage-web</artifactId>
10     <packaging>war</packaging>
11     
12     <build>
13         <plugins>
14             <plugin>
15                 <groupId>org.apache.maven.plugins</groupId>
16                 <artifactId>maven-war-plugin</artifactId>
17                 <version>3.0.0</version>
18                 <configuration>
19                     <failOnMissingWebXml>false</failOnMissingWebXml>
20                 </configuration>
21             </plugin>
22         </plugins>
23     </build>
24     
25 </project>

 

 

 

聚合工程的完整目錄

 

 

 

父工程pom.xml內容

 

 

硬盤中聚合工程存儲目錄結構:

 

相關文章
相關標籤/搜索