一. 自动发布构件到远程仓库 1. 在工程的pom.xml中添加:
<distributionManagement> <repository> <id>releases</id><!--这个ID需要与你的release仓库的Repository ID一致--> <url>http://172.18.19.157:8081/nexus/content/repositories/releases</url> </repository> <snapshotRepository> <id>snapshots</id><!--这个ID需要与你的snapshots仓库的Repository ID一致--> <url>http://172.18.19.157:8081/nexus/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement> 123456789101112 1234567891011122.修改$MAVEN_HOME\conf目录下的settings.xml配置文件,添加如下配置:
<servers> <server> <id>releases</id> <username>admin</username> <password>dev123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>dev123</password> </server> </servers> 123456789101112 1234567891011123.打开windows命令行,在工程所在目录下执行
mvn deploy 1 1所部署的包就自动上传到了nexus安装目录下的
二.配置Maven从Nexus下载构件 1.在POM中配置Nexus私服,这样的配置只对当前的Maven项目有效。
<repositories> <repository> <id>public</id> <name>Team Maven Repository</name> <url>http://172.18.19.157:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> 12345678910111213 123456789101112132.在settings.xml中配置profile元素,这样就能让本机所有的Maven项目都使用自己的Maven私服。
