Maven deploy上传jar包到远程仓库
1. 前言
Maven
仓库管理也叫 Maven
私服或者代理仓库。使用 Maven
私服有两个目的:
- 私服是一个介于开发者和远程仓库之间的代理;
- 私服可以用来部署公司自己的
jar
;
2. Nexus
介绍
Nexus
是一个强大的 Maven
仓库管理工具,使用 Nexus
可以方便的管理内部仓库同时简化外部仓库的访问。
2.1 Nexus
安装
- 下载
下载地址:www.sonatype.com/download-os…
- 解压
将下载下来的压缩包,拷贝到一个没有中文的路径下,然后解压。
- 启动
解压之后,打开 cmd
窗口(以管理员身份打开 cmd 窗口),然后定位了 nexus 解压目录,执行 nexus.exe/run
命令启动服务。这个启动稍微有点慢,大概有 1 两分钟的样子。
启动成功后,浏览器输入 http://lcoalhost:8081
打开管理页面。
打开管理页面后,点击右上角上的登录按钮进行登录,默认的用户名/密码是 admin/admin123
。当然,用户也可以点击设置按钮,手动配置其他用户。
点击 Repositories 可以查看仓库详细信息:
3. 仓库类型
名称 | 说明 |
---|---|
proxy | 表示这个仓库是一个远程仓库的代理,最典型的就是代理 Maven 中央仓库 |
hosted | 宿主仓库,公司自己开发的一些 jar 存放在宿主仓库中,以及一些在 Maven 中央仓库上没有的 jar |
group | 仓库组,包含代理仓库和宿主仓库 |
virtual | 虚拟仓库 |
4. 上传 jar
上传 jar,配置两个地方:
Maven 的 conf/settings.xml
文件配置:
1 2 3 4 5 6 7 8 9 10 | <server> <id>releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin123</password> </server> |
在要上传 jar 的项目的 pom.xml
文件中,配置上传路径:
1 2 3 4 5 6 7 8 9 10 | <distributionManagement> <repository> <id>releases</id> <url>http: //localhost:8081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>snapshots</id> <url>http: //localhost:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement> |
配置完成后,点击 deploy
按钮,或者执行 mvn deploy
命令就可以将 jar
上传到私服上。
5. 跳过某个module
I don’t want to deploy one of the artifacts in my multi-module build. Can I skip deployment?
Yes, you can skip deployment of individual modules by configuring the Deploy Plugin as follows:
12345678<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>
2.8
.
2
</version>
<configuration>
<skip>
true
</skip>
</configuration>
</plugin>
参考:http://maven.apache.org/plugins/maven-deploy-plugin/faq.html
6. 下载私服上的
jar
直接在项目中添加依赖,添加完成后,额外增加私服地址即可:
123456789101112<repositories>
<repository>
<id>local-repository</id>
<url>http:
//localhost:8081/repository/maven-public/</url>
<releases>
<enabled>
true
</enabled>
</releases>
<snapshots>
<enabled>
true
</enabled>
</snapshots>
</repository>
</repositories>
原文地址 https://blog.csdn.net/lijingjingchn/article/details/105510584?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-105510584-blog-128469326.235^v31^pc_relevant_default_base3&spm=1001.2101.3001.4242.1&utm_relevant_index=3
//其他相关文章地址
https://blog.csdn.net/weixin_43886640/article/details/123714553
https://blog.csdn.net/xukaiqiang123/article/details/129418655
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)