一、分模块
1)、当拥有多模块时,创建统一jar包版本管理模块,此模块作为所有模块的父模块。(Maven project)
2)、创建子模块(在父模块上右键——>New——>Maven Mode)
※jar工程上图即可,当创建Web服务时:如上图——>Next——>如下图
二、多模块,多Web应用,合并为一个war包。(注意:需要对依赖的项目先maven install后再使用)
1)、当需要在Web工程中,加入jar工程时,只需要在Web工程引入jar工程坐标。在Web工程pom.xml文件中添加依赖
<dependency>
<groupId>com.yintong.parent</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
2)、合并Web工程为一个war包。(例如:将productWeb工程合并到customerWeb工程中)
①、在customerWeb工程的pom.xml文件中添加productWeb工程的war坐标。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<overlays>
<overlay>
<!--主要修改此处-->
<groupId>com.yintong.parent</groupId>
<artifactId>productWeb</artifactId>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
②、在customerWeb项目的pom.xml文件中添加productWeb项目的依赖。(type属性不能忽略)
<dependency>
<groupId>com.yintong.parent</groupId>
<artifactId>productWeb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
③、项目启动插入jetty插件(运行:run as ——> maven build... ——>在goals中输入:clean jetty:run即可)
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.14.v20131031</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopPort>9999</stopPort>
<webAppConfig>
<!-- 项目启动目录:http://localhost:9080/customer/ 可修改-->
<contextPath>/customer</contextPath>
</webAppConfig>
<connectors>
<connector
implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<!-- 项目启动端口:不能被占用,可修改 -->
<port>9080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
④、注意事项:查看最终war包得出结论,当多个web项目存在相同路径相同文件名时,总的会覆盖分支的即customerWeb会覆盖productWeb的,如果总的没有,看合并的顺序,以第一个文件为主。