我们在开发2个以上模块的时候,每个模块都是一个Maven Project。比如搜索平台,学习平台,考试平台。开发的时候可以自己管自己独立编译,测试,运行。但如果想要将他们整合起来,我们就需要一个聚合工程。
创建聚合工程

创建模块





给模块添加jar,使用maven的方式,但坐标方式有时是找不到需要的jar就会出错:
Missing artifact net.sourceforge:pinyin4j:jar:2.5.0
解决办法,从网络下载该jar包然后在cmd窗口使用 maven命令打入仓库中。
mvn install:install-file -Dfile=F:\Maven\LocalRepository\pinyin4j-2.5.0.jar -DgroupId=net.sourceforge.pinyin4j -DartifactId=pinyin4j -Dversion=2.5.0 -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true
mvn install:install-file -Dfile=F:\Maven\LocalRepository\ojdbc6.jar -DgroupId=com.oracle.ojdbc6 -DartifactId=ojdbc6 -Dversion=11.2.0.1.0 -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true
mvn install:install-file
-Dfile=jar包的位置
-DgroupId=上面的groupId
-DartifactId=上面的artifactId
-Dversion=上面的version
-Dpackaging=jar
然后在pom.xml中引入:
<dependency>
<groupId>net.sourceforge.pinyin4j</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.0</version>
</dependency>
在聚合工程的pom.xml中:
<!-- 设定子模块的目录,目录中要有pom.xml,使用相对路径 -->
<modules>
<module>spring-mybatis</module>
<module>yyptutil</module>
<module>yyptProject</module>
</modules>
在子模块工程的pom.xml中:
<parent>
<groupId>yypt</groupId>
<artifactId>yyptParent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>yyptutil</artifactId>
最后从CMD窗口进入到聚合工程的目录执行mvn install命令就可以将各个子模块工程合并到一起打成war包。
网友评论