maven pom.xml学习

本文详细介绍了如何使用Maven进行项目的部署,并解释了配置文件pom.xml与settings.xml中的关键节点,包括repository、distributionManagement等,以实现组件的远程仓库上传。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、Maven内置变量说明:

  • ${basedir} 项目根目录
  • ${project.build.directory} 构建目录,缺省为target
  • ${project.build.outputDirectory} 构建过程输出目录,缺省为target/classes
  • ${project.build.finalName} 产出物名称,缺省为${project.artifactId}-${project.version}
  • ${project.packaging} 打包类型,缺省为jar
  • ${project.xxx} 当前pom文件的任意节点的内容

如果想上传(deploy)组件到远程仓库,需要配置两步:

  (1)在项目的pom中配置distributionManagement节点,如下:

<project>

  1. <distributionManagement>

  2. <repository>

  3. <id>acfunRepo</id>

  4. <url>http://nexus.acfun.tv/nexus/content/repositories/AcFun-Release/</url>

  5. </repository>

  6. <snapshotRepository>

  7. <id>acfunRepo</id>

  8. <url>http://nexus.acfun.tv/nexus/content/repositories/AcFun-Snapshot/</url>

  9. </snapshotRepository>

  10. </distributionManagement>  </project>

(2)在settings.xml文件中配置所上传到的仓库的用户名密码(server节点)

  1. <servers>

  2. <server>

  3. <id>acfunRepo</id>

  4. <username>acfun</username>

  5. <password>acfun123</password>

  6. </server>

  7. </servers>

 

这里的远程仓库一般指的是中央仓库或者私服,是拉取组件用的仓库。二者都既能配置在settings.xml文件,也可以配置在项目的pom文件中。但是,如果配置中央仓库,则建议配置在settings文件中,方便大家共用;如果配置私服(nexus),则建议配置在项目的pom中,方便保持项目的灵活性。

  下面则以私服(nexus)为例,展示分别在settings.xml中与pom中的配置方法:

  3.1 在pom中配置(比较简单)

  1. <project>

  2. ......

  3. <repositories>

  4. <repository>

  5. <id>acfunnexus</id>

  6. <url>http://nexus.acfun.tv/nexus/content/groups/public/</url>

  7. <layout>default</layout>

  8. <releases>

  9. <enabled>true</enabled>

  10. </releases>

  11. <snapshots>

  12. <enabled>true</enabled>

  13. </snapshots>

  14. </repository>

  15. </repositories>

  16. ......

  17. </project>

3.2 在settings.xml中配置(需要两步)

  它不支持pom中的中的<repositories>及<pluginRepositories>元素,所以我们需要利用profileactiveProfile节点来完成,如下:

  1. <settings>  

  2.   ...   

  3.   <profiles>  

  4.     <profile>  

  5.       <id>dev</id> 

  6. <repositories>

  7. <repository>

  8. <id>maven-net-cn</id>

  9. <name>MavenChinaMirror</name>

  10. <url>http://repo2.maven.org/maven2/</url>

  11. <releases>

  12. <enabled>true</enabled>

  13. </releases>

  14. <snapshots>

  15. <enabled>false</enabled>

  16. </snapshots>

  17. </repository>

  18. </repositories>

  19. <pluginRepositories>

  20. <pluginRepository>

  21. <id>maven-net-cn</id>

  22. <name>MavenChinaMirror</name>

  23. <url>http://repo2.maven.org/maven2/</url>

  24. <releases>

  25. <enabled>true</enabled>

  26. </releases>

  27. <snapshots>

  28. <enabled>false</enabled>

  29. </snapshots>

  30. </pluginRepository>

  31. </pluginRepositories>

  32.   

  33.     </profile>  

  34.   </profiles>  

  35.   <activeProfiles>  

  36.     <activeProfile>dev</activeProfile>  

  37.   </activeProfiles>  

  38.   ...   

  39. </settings>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值