利用maven构建多模块项目

1. 先单独构建各模块为一个独立的项目。
jar项目:

mvn archetype:create -DgroupId=org.sonatype.mavenbook.weather -DartifactId=simple-weather

 

war项目:

mvn archetype:create -DgroupId=org.sonatype.mavenbook.web -DartifactId=simple-webapp 
-DpackageName=org.sonatype.mavenbook -DarchetypeArtifactId=maven-archetype-webapp
 

2. 构建父项目,并将各子模块文件拷贝到父项目路径下。

mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch06 -DartifactId=simple-parent 
-DpackageName=org.sonatype.mavenbook -DarchetypeArtifactId=maven-archetype-webapp
 

3. 修改父项目pom.xml与各子模块pom.xml配置对应关系。

父项目的pom.xml

<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.mavenbook.ch06</groupId>
<artifactId>simple-parent</artifactId>
<packaging>pom </packaging>
<version>1.0</version>
<name>simple-parent Maven Webapp</name>
<url>http://maven.apache.org</url>
<modules>
<module>simple-weather</module>
<module>simple-webapp</module>
</modules
>

 

子项目的pom.xml

<parent>
        <groupId>com.your-company.xxxx</groupId>
        <artifactId>xxxx</artifactId>
        <version>1.0</version>
        <relativePath>../pom.xml</relativePath>
 </parent>

...

<dependency>
      <groupId>org.sonatype.mavenbook.ch06</groupId>
      <artifactId>simple-weather</artifactId>
      <version>1.0</version>
 </dependency
>

 

4. 在父项目路径下执行:mvn eclipse:m2eclipse

5.在配有m2eclipse 插件的eclipse中导入父项目路径下的项目,导入为m2eclipse project。

 

enjoy!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值