pom标签详解

3.pom标签详解

 

3.1 项目坐标标签:

   

  1. <project xmlns="http://maven.apache.org/POM/4.0.0"  
  2.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  
  4.                       http://maven.apache.org/maven-v4_0_0.xsd">  
  5.   <modelVersion>4.0.0</modelVersion>  
  6.   <groupId>org.codehaus.mojo</groupId>  
  7.   <artifactId>my-project</artifactId>  
  8.   <version>1.0</version>  
  9.   <packaging>war</packaging>  
  10. </project>  
  1. groupId : 组织标识,例如:org.codehaus.mojo,在M2_REPO目录下,将是: org/codehaus/mojo目录。
  2. artifactId : 项目名称,例如:my-project,在M2_REPO目录下,将是:org/codehaus/mojo/my-project目录。
  3. version : 版本号,例如:1.0,在M2_REPO目录下,将是:org/codehaus/mojo/my-project/1.0目录。
  4. packaging : 打包的格式,可以为:pom , jar , maven-plugin , ejb , war , ear , rar , par
  5. modelVersion:定义pom版本号,版本号有一系列的规则
   3.2 依赖标签:
(依赖关系列表(dependency list)是POM的重要部分,也就是我们项目对jar包的管理)
Xml代码 
  1. <dependencies>  
  2.    <dependency>  
  3.      <groupId>junit</groupId>  
  4.      <artifactId>junit</artifactId>  
  5.      <version>4.0</version>  
  6.      <scope>test</scope>  
  7.    </dependency>  
  8.    …  
  9.  </dependencies>  
  1. groupId , artifactId , version :引用的坐标
  2. scope : compile(default),provided,runtime,test,system  依赖的范围
  3. exclusions  需要排除的依赖的jar包
3.3 继承和聚合(子pom对父pom依赖 和 父项目对模块的依赖)
  1. <project xmlns="http://maven.apache.org/POM/4.0.0"  
  2.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  
  4.                       http://maven.apache.org/maven-v4_0_0.xsd">  
  5.   <modelVersion>4.0.0</modelVersion>  
  6.   <groupId>org.maven.my</groupId>  
  7.   <artifactId>${projectName}-parent</artifactId>  
  8.   <version>2.0</version> 
  9.   <!-- 定义项目有哪些子模块 --> 
  10.   <modules>  
  11.     <module>my-spring-web<module>  
  12.     <module>my-spring-service<module>  
  13.     <module>my-spring-common<module>  
  14.     <module>my-spring-dao<module>  
  15.   </modules>  
  16. </project>  
 3.4 项目构建build时标签:
(可以帮我们指定 需要的maven插件,主要标签:Resources和Plugins
    Resources:用于排除或包含某些资源文件
    可以用于解决 我们部署测试和线上 服务时,资源文件配置的隔离依赖:-Ponline | -Plocal
Xml代码   收藏代码
  1. <build>  
  2.         <!-- 开启资源文件过滤 -->  
  3.         <resources>  
  4.             <resource>  
  5.                 <directory>${project.basedir}/src/main/resources</directory>  
  6.                 <filtering>true</filtering>  
  7.             </resource>  
  8.         </resources>  
  9. </build>  
  10. <!-- 指定资源文件路径 -->  
  11. <profiles>  
  12.         <!--测试配置 -->  
  13.         <profile>  
  14.             <id>local</id>  
  15.             <activation>  
  16.                 <activeByDefault>true</activeByDefault>  
  17.             </activation>  
  18.             <build>  
  19.                 <filters>  
  20.                     <filter>${project.basedir}/src/main/swap/local.properties</filter>  
  21.                 </filters>  
  22.             </build>  
  23.         </profile>  
  24.         <!-- 线上配置 -->  
  25.         <profile>  
  26.             <id>online</id>  
  27.             <activation>  
  28.                 <activeByDefault>false</activeByDefault>  
  29.             </activation>  
  30.             <build>  
  31.                 <filters>  
  32.                     <filter>${project.basedir}/src/main/swap/online.properties</filter>  
  33.                 </filters>  
  34.             </build>  
  35.         </profile>  
 
 Plugins:设置构建的插件
  1. <build>  
  2.    …  
  3.    <!-- 配置maven在运行时 需要依赖的插件,我们平常可以配jetty插件或者assemebly插件等-->
  4.    <plugins>  
  5.      <plugin>  
  6.        <groupId>org.apache.maven.plugins</groupId>  
  7.        <artifactId>maven-jar-plugin</artifactId>  
  8.        <version>2.0</version>  
  9.        <extensions>false</extensions>  
  10.        <inherited>true</inherited>  
  11.        <configuration>  
  12.          <classifier>test</classifier>  
  13.        </configuration>  
  14.        <dependencies>…</dependencies>  
  15.        <executions>…</executions>  
  16.      </plugin>  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值