首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >jar包传到Nexus私服中

jar包传到Nexus私服中

原创
作者头像
陈不成i
修改于 2021-06-24 18:04:56
修改于 2021-06-24 18:04:56
9370
举报
文章被收录于专栏:ops技术分享ops技术分享

一.简介

开发完项目后, 将项目打的jar包依赖,发布到Nexus私服中

二.操作

1.如果本机安装了Maven服务, 可在${MAVEN_HOME}/conf/setting.xml中指定私服相关的配置

  1. <!-- 在servers标签下配置server, 包括: 私服的用户名和密码, 在deploy项目时需要用到 -->
  2. <server>
  3. <id>releases</id>
  4. <username>admin</username>
  5. <password>admin123</password>
  6. </server>
  7. <server>
  8. <id>snapshots</id>
  9. <username>admin</username>
  10. <password>admin123</password>
  11. </server>
  12. <!-- 在profiles标签下配置profile, 包括: 私服所配的仓库、各个插件的仓库地址 -->
  13. <profile>
  14. <!-- profile的id -->
  15. <id>dev</id>
  16. <repositories>
  17. <repository>
  18. <!-- 仓库id, Repositories可以配置多个仓库, 要确保id不重复 -->
  19. <id>nexus</id>
  20. <!-- 仓库地址, 即nexus仓库组的地址 -->
  21. <url>http://ip:port/nexus/content/groups/public/</url>
  22. <!-- 是否下载Releases构件 -->
  23. <releases>
  24. <enabled>true</enabled>
  25. </releases>
  26. <!-- 是否下载Snapshots构件 -->
  27. <snapshots>
  28. <enabled>true</enabled>
  29. </snapshots>
  30. </repository>
  31. </repositories>
  32. <pluginRepositories>
  33. <!-- 插件仓库, Maven的运行依赖插件, 也需要从私服下载插件 -->
  34. <pluginRepository>
  35. <!-- 插件仓库的id不允许重复, 如果重复, 后配置的优先 -->
  36. <id>public</id>
  37. <name>Public Repositories</name>
  38. <url>http://ip:port/nexus/content/groups/public/</url>
  39. </pluginRepository>
  40. </pluginRepositories>
  41. </profile>
  42. <!-- 还需指定联网仓库, 保证本私服中没有相关jar包或插件时可联网获取 -->
  43. <profile>
  44. <id>internet</id>
  45. <repositories>
  46. <repository>
  47. <id>nexus-aliyun</id>
  48. <name>Nexus aliyun</name>
  49. <layout>default</layout>
  50. <!-- 这里配置阿里云的仓库 -->
  51. <url>http://maven.aliyun.com/nexus/content/groups/public</url>
  52. <snapshots>
  53. <enabled>false</enabled>
  54. </snapshots>
  55. <releases>
  56. <enabled>true</enabled>
  57. </releases>
  58. </repository>
  59. </repositories>
  60. </profile>

2.在项目的pom.xml中的一级标签project下添加如下内容:

  1. <!-- 发布选项: id必须与setting.xml文件中server的id相同 -->
  2. <distributionManagement>
  3. <repository>
  4. <id>releases</id>
  5. <name>display</name>
  6. <url>http://ip:port/nexus/content/repositories/releases/</url>
  7. </repository>
  8. <snapshotRepository>
  9. <id>snapshots</id>
  10. <name>display</name>
  11. <url>http://ip:port/nexus/content/repositories/snapshots/</url>
  12. </snapshotRepository>
  13. </distributionManagement>

3.使用IDEA发布项目 以IDEA为例, 选中项目, 右键 -> Run Maven -> deploy 或者在右边栏选中Maven栏目, 点击项目 -> Lifecycle -> deploy, 执行即可将项目发布到仓库中去

4.使用发布项目 /usr/local/maven/bin/mvn clean deploy -e -U

注意: 仓库中不能存在与当前项目名称+版本号相同的项目, 否则将导致出错: Bad Request: 400

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

目录
  • 一.简介
  • 二.操作
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档