Maven 聚合项目创建

第一步:创建父工程

右击空白处,new 创建新的 maven 工程

这里跳过默认的骨架,使用自动义的骨架

这里父工程必须使用pom打包方式

第二步:创建子工程

右击空白处,new创建新maven工程

跳过默认骨架,输入子工程名,并引用父工程

定义子工程,这里是以表现层为例,是web工程,所以打包方式为war,如果是其他非web工程就可以打包成jar,这一点需要注意。

其他工程步骤类似,需要注意的是打包方式的选择。

工程创建完成后现象:

所有的子工程目录不是单独的存在,而是直接保存在父工程目录下。

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内容

硬盘中聚合工程存储目录结构:

 

猜你喜欢

转载自www.cnblogs.com/sky-jie/p/9901477.html
今日推荐