1 安装 nexus
2 启动,登录
默认地址:http://localhost:8081
默认用户名密码,admin / admin123

3 创建账号
一般用来上传jar使用

4 配置仓库
一般建三种类型的仓库:
中央仓库:type选择proxy,用来同步所有的中央仓库jar,比如spring,org等等
私有仓库:用来上传第三方jar和私有的jar,比如项目核心jar
组合仓库: 将中央仓库,私有仓库合并在一起,开发人员本地配置这个地址就可以下载所有的jar包了。

4.1 建立一个中央仓库,用阿里云
4.1.1 Type选择Proxy

最新版的阿里云仓库地址是:https://maven.aliyun.com/repository/public
https需要添加证书,点击“View Certificate”
4.1.2 创建过后

4.2 创建私有仓库

因为要上传自己的jar,所以红色部分,选择允许。
4.3 创建组合仓库

一般将私有仓库和中央仓库添加进来就可以了。
4.3.1 组合仓库地址

5 开发人员本地配置
5.1 maven 的配置文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="[http://maven.apache.org/SETTINGS/1.0.0](http://maven.apache.org/SETTINGS/1.0.0)"
xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"
xsi:schemaLocation="[http://maven.apache.org/SETTINGS/1.0.0](http://maven.apache.org/SETTINGS/1.0.0)[http://maven.apache.org/xsd/settings-1.0.0.xsd](http://maven.apache.org/xsd/settings-1.0.0.xsd)">
<localRepository>/Users/zhangjh/work/project/jar</localRepository>
<servers>
<server>
<id>lms-core</id>
<username>zhangjh</username>
<password>123456</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<url>[http://localhost:8081/repository/lms/](http://localhost:8081/repository/lms/)</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
</profiles>
</settings>
5.2 内容解释
servers的内容为上传jar时使用
其中,username和password是第3步创建的账号;
id用来执行上传命令时需要,看下面。
<mirrorOf>central</mirrorOf>
这个一定要配置成central
5.3.上传jar
5.3.1 上传命令
mvn deploy:deploy-file -DgroupId=com.midea.lms -DartifactId=data-client -Dversion=0.0.4 -Dpackaging=jar -Dfile=/Users/zhangjh/Downloads/data-client-0.0.4.jar -Durl=http://localhost:8081/repository/lmx-core/ -DrepositoryId=lms-core
5.3.2 解释
对比项目中的pom.xml更好解释

-DgroupId=com.midea.lms -DartifactId=data-client -Dversion=0.0.4 分别对应上面三个信息
-Durl=http://localhost:8081/repository/lmx-core/ 为4.2 创建的私有仓库地址,
-DrepositoryId=lms-core 为 5.1maven 的配置文件中server指定的id,通过它找到用户名和密码,进行鉴权上传。
5.4 idea配置
idea指定到maven的路径,配置文件

5.5 下载jar
修改一下pom.xml内容一般都会下载成功。
如果在idea的Maven Projects中,jar始终是红色,就去本地jar存放的目录,把对应的文件夹删除,重新刷新下载(其实看到本地只有update文件)。

网友评论