将自己的项目上传到私服
上传到单独的仓库
一:配置maven的setting.xml
// #在servers标签下配置
<server>
<id>nexus</id>
<username>admin</username>
<password>123456</password>
</server>
二:配置pom.xml
注意点:nexus为你指定的仓库id,可以随意命名。但是必须下面pom中的id一致,才可以校验权限。例如项目的pom.xml中
// #在servers标签下配置
<distributionManagement>
<!-- 发布到那个仓库,id对应maven中server下的id做验证-->
<repository>
<id>nexus</id>
<url>http://192.168.1.242:8081/repository/release-local/</url>
</repository>
</distributionManagement>
idea直接使用maven插件(前提idea配置了maven)
即可发布到私服仓库
查看私服仓库
上传到指定的仓库
1:maven中settings.xml配置
想要将项目上传到不同的仓库,可使用如下配置。
<server>
<id>snapshot-local</id>
<username>admin</username>
<password>123456</password>
</server>
<server>
<id>release-local</id>
<username>admin</username>
<password>123456</password>
</server>
2:pom.xml配置
<distributionManagement>
<!-- 发布到那个仓库,id对应maven中server下的id做验证-->
<repository>
<id>release-local</id>
<url>http://192.168.1.242:8081/repository/release-local/</url>
</repository>
<snapshotRepository>
<id>snapshot-local</id>
<url>http://192.168.1.242:8081/repository/snapshot-local/</url>
</snapshotRepository>
</distributionManagement>
注意点:上传到snapshot(快照仓库),版本号必须是x.x-SNAPSHOT.jar,不然无法上传。上传到release类型的仓库则无版本号要求。
上述配置项中的url为上篇博客配置的仓库地址: 机票.
使用页面upload上传
将私服的项目下载到本地
非SNAPSHOT版本
一:配置maven的setting.xml
<server>
<id>nexus</id>
<username>admin</username>
<password>123456</password>
</server>
<server>
<id>third3</id>
<username>dev</username>
<password>123456</password>
</server>
<server>
<id>release-local</id>
<username>admin</username>
<password>123456</password>
</server>
// #在mirrors标签下配置
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.1.242:8081/repository/maven-public/</url>
</mirror>
<mirror>
<id>third3</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.1.242:8081/repository/third/</url>
</mirror>
<mirror>
<id>release-local</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.1.242:8081/repository/release-local/</url>
</mirror>
mirror的id对应上面server标签的id,进行权限验证
mirror的id对应上面server标签的id,进行权限验证
mirror的id对应上面server标签的id,进行权限验证
重要的事情数三遍,但是如果都将私有仓库加到了maven-public中,即配置一个maven-public地址即可从私服中下载项目。
SNAPSHOT版本
mirror的配置,只对release有效,对于snapshot无效的。
所以下载该版本的jar需要以下配置(二选一)
1:pom.xml配置
<repositories>
<repository>
<id>nexus</id>
<url>http://192.168.1.242:8081/repository/snapshot-local/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
2:maven中settings.xml配置
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>Nexus</id>
<url>http://192.168.1.242:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>