<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
2、pom.xml中配置 distributionManagement块,执行deploy就可以了 3、如果要发布到 snapshotRepository的话,只需要保证项目的版本最后是-SNAPSHOT结尾就会在发布的时候自动发布到配置的snapshotRepository下。 默认的nexus用户名是admin密码是admin123,登录后可以看到有一个depolyment用户,可以设置一个密码,然后用depolyment的用户来发布到我们自己的nexus私有仓库。本文使用nexus这个名字作为私服的主机名。如果你也想直接使用nexus访问到私服,可以设置hosts文件。 下面我列出在项目中的pom:
<repositories>
<!-- 本地稳定版本构件库-->
<repository>
<id>releases</id>
<name>releases</name>
<url>http://nexus:8081/nexus/content/repositories/releases</url>
</repository>
<!-- 本地临时版本构件库-->
<repository>
<id>snapshots</id>
<name>snapshots</name>
<url>http://nexus:8081/nexus/content/repositories/snapshots</url>
</repository>
</repositories>
<!-- 发布到本地镜像仓库 -->
<distributionManagement>
<repository>
<id>releases</id>
<name>releases</name>
<url>http://nexus:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>snapshots</name>
<url>http://nexus:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
配合使用profiles可以灵活的区分不同的环境动态设置配置
<profiles>
<profile>
<id>dev</id>
<properties>
<jdbc_driverClass>com.mysql.jdbc.Driver</jdbc_driverClass>
<jdbc_host>localhost</jdbc_host>
<jdbc_port>3306</jdbc_port>
<jdbc_dbname>test</jdbc_dbname>
<jdbc_username>root</jdbc_username>
<jdbc_password>123456</jdbc_password>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<os>
<family>linux</family>
</os>
</activation>
<properties>
<log4j_log_path>/var/log</log4j_log_path>
</properties>
</profile>
</profiles>
同时如果直接从远程仓库下载依赖太慢,在开发团队中,使用nexus开启central的proxy仓库是一个很好的办法,开启的办法很简单,就是使用admin登录nexus的后台,然后设置Central的配置,讲下载索引的开关打开,并且将这个仓库添加到Publish的列表中,然后在本地的maven配置文件中,设置mirror。
<mirror>
<id>centralMirror</id>
<mirrorOf>central</mirrorOf>
<name>Central Repository Mirror Server.</name>
<url>http://nexus:8081/nexus/content/repositories/central</url>
</mirror>
tips:
本文由wp2Blog导入,原文链接:http://devonios.com/%e5%b0%86%e6%9e%84%e4%bb%b6%e5%8f%91%e5%b8%83%e5%88%b0%e7%a7%81%e6%9c%89%e7%9a%84nexus-maven-%e4%bb%93%e5%ba%93.html