因工作需要,需要搭建公司自己的私有仓库,存储自己的私有jar包,所以研究了下
一、环境准备
1、下载并安装nexus,然后启动项目,这部分攻略网上很多,而且基本上都是正确的,此处不做梳理
2、登录127.0.0.1:8081,默认用户名密码是admin/admin123
3、创建私有仓库
仓库类型有hosted、proxy、group,hosted-本地存储。像官方仓库一样提供本地私库功能;proxy-提供代理其它仓库的类型;group-组类型,能够组合多个仓库为一个地址提供服务,所以这里选hosted。
保存后在列表页面点击新创建的仓库,进到详细页面,查看仓库地址并妥善保存,后面会用到
4、创建角色,只拥有新增仓库的读取权限。
5、创建拥有该角色的用户
这样仓库就创建好了,接下来是使用,首先是导入jar包,目前只研究了网页导入
二、私有jar包上传
1、查找上传入口
2、选择jar包并维护信息,如果勾选了Generate a POM file with these coordinates,会自动生成pom文件信息
3、确认jar包,如果按照步骤看到如下信息,表示已经上传成功
三、本地导出
1、本地maven改造,修改setting文件
首先维护用户信息,记住此处配置的server.id,后面会用到
<servers> <server> <id>dingxf-third_part</id> <username>dingxf</username> <password>dingxf</password> </server> </servers>
然后配置仓库信息,首先在<profiles></profiles>中维护以下信息
<profile> <!-- 自定义不重复id --> <id>dingxf</id> <repositories> <repository> <!-- 维护的server.id 如果维护错误会报错:Not authorized , ReasonPhrase:Unauthorized --> <id>dingxf-third_part</id> <!-- 自定义name名,无要求 --> <name>dingxf</name> <!-- 一.3中保存的地址名,如果维护错误会报错:Could not find artifact jar包 in wecredo-third_part (http://url地址) --> <url>http://182.92.122.172:8081/repository/third_part/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <!-- 维护的server.id 如果维护错误会报错:Not authorized , ReasonPhrase:Unauthorized --> <id>dingxf-third_part</id> <!-- 自定义name名,无要求 --> <name>dingxf</name> <!-- 一.3中保存的地址名,如果维护错误会报错:Could not find artifact jar包 in wecredo-third_part (http://url地址) --> <url>http://182.92.122.172:8081/repository/third_part/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile>
然后在最外层<settings></settings>中维护以下信息
<activeProfiles> <!-- profile.id 如果不维护或错误会报错:Could not find artifact xxxxx in central (https://repo.maven.apache.org/maven2),此时私有仓库不起作用 --> <activeProfile>dingxf</activeProfile>
</activeProfiles>
2、然后项目的pom.xml中维护以下信息
<distributionManagement> <repository> <!-- 维护的server.id 如果维护错误会报错:Not authorized , ReasonPhrase:Unauthorized --> <id>dingxf-third_part</id> <!-- 自定义name名,无要求 --> <name>dingxf-third_part</name> <!-- 一.3中保存的地址名,如果维护错误会报错:Could not find artifact jar包 in dingxf-third_part (http://url地址) --> <url>http://182.92.122.172:8081/repository/third_part/</url> </repository> <snapshotRepository> <!-- 维护的server.id 如果维护错误会报错:Not authorized , ReasonPhrase:Unauthorized --> <id>dingxf-third_part</id> <!-- 自定义name名,无要求 --> <name>dingxf-third_part</name> <!-- 一.3中保存的地址名,如果维护错误会报错:Could not find artifact jar包 in dingxf-third_part (http://url地址) --> <url>http://182.92.122.172:8081/repository/third_part/</url> </snapshotRepository> </distributionManagement>