MAVEN 创建父子项目,聚合

本文介绍了如何使用Maven创建父子项目,并通过配置modules实现子项目的聚合。在创建过程中,详细讲述了如何设置groupId、artifactId以及packaging,以及解决可能出现的错误,如Invalid project description。此外,还讲解了父项目和子项目pom.xml文件的配置,包括dependency管理和相对路径引用,以确保子项目能正确引用其他模块的类。
        最近做了maven的一些实验,这一次我们就来创建maven父子项目,首先我们应该建一个普通项目util,一个common项目,common中需要用到util的项目中的类,这时候我们就需要建立父子项目的关系了。spring 扫描jar包的问题,如果jar包没有directory entry的话,则不会扫描,也就是说如果我们的项目中加入注解,然后用spring扫描可能扫描不到,必须在bean中配置,或者是mvn install 的时候就自动选择directory entry,还有一种方式就是install的时候将多个war包打到一个包中 
        首先建立一个maven quickstart项目util,然后新建common的项目,然后再新建一个maven simple project
                     
 选择next并且填写groupId,artifactId,以及packing的形式为pom 
创建成功,但是我在某一次的实验的时候创建失败,出现如下的错误
         
        Failed to create project cuparent1 invalid project description,出错的原因是我Use default workSpace location 我选择位置导致出现了错误。
        新建maven   simple project 的第一个页面不要做额外的操作
       接着我们在cuparent中配置聚合,即modules,这样我们install cuparent的时候会自动install子项目
    我们在 cuparent配置modules如下
         
<project xmlns=" http://maven.apache.org/POM/4.0.0 " xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance " xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0   http://maven.apache.org/xsd/maven-4.0.0.xsd ">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.testParent</groupId>

  <artifactId>cuparent</artifactId>

  <version>1.0</version>

  <packaging>pom</packaging>

  <modules>

   <module>../util</module>

   <module>../common</module>

  </modules>

</project>

在common中的配置如下
<project xmlns=" http://maven.apache.org/POM/4.0.0" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0  http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
  <modelVersion>4.0.0</modelVersion> 

  <artifactId>common</artifactId> 
  <version>0.0.1-SNAPSHOT</version> 
  <packaging>jar</packaging> 

  <name>common</name> 
  <url> http://maven.apache.org</url> 

<parent> 
<groupId>com.testParent</groupId> 
<artifactId>cuparent</artifactId> 
<version>1.0</version> 
<relativePath>../cuparent/pom.xml</relativePath> 
</parent> 

  <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
  </properties> 

  <dependencies> 
    <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>3.8.1</version> 
      <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.testParent</groupId> 
     <artifactId>util</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
    </dependency> 
  </dependencies> 
</project> 



在util的项目中配置如下
<project xmlns=" http://maven.apache.org/POM/4.0.0" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0  http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
  <modelVersion>4.0.0</modelVersion> 

  <artifactId>util</artifactId> 
  <version>0.0.1-SNAPSHOT</version> 
  <packaging>jar</packaging> 

  <name>util</name> 
  <url> http://maven.apache.org</url> 
   
  <parent> 
   <groupId>com.testParent</groupId> 
   <artifactId>cuparent</artifactId> 
   <version>1.0</version> 
   <relativePath>../cuparent/pom.xml</relativePath> 
  </parent> 

  <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
  </properties> 

  <dependencies> 
    <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>3.8.1</version> 
      <scope>test</scope> 
    </dependency> 
  </dependencies> 
</project> 
这样一个父子聚合的项目就搭建完成了 over
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值