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 文件配置:
<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 文件中,配置上传路径:
<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:<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直接在项目中添加依赖,添加完成后,额外增加私服地址即可:
<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

浙公网安备 33010602011771号