在Idea pom.xml中使用distributionManagement
1.pom.xml文件添加distributionManagement節點
<!-- 使用分發管理將本項目打成jar包,直接上傳到指定服務器 --> <distributionManagement> <!--正式版本--> <repository> <!-- nexus服務器中用戶名:在settings.xml中<server>的id--> <id>nexus-releases</id> <!-- 這個名稱自己定義 --> <name>Release repository</name> <url>http://192.168.1.xxx:8081/repository/yang/</url> </repository> <!--快照 <snapshotRepository> <id>nexus-snapshots</id> <name>Snapshots repository</name> <url>http://192.168.1.xxx:8081/repository/yang/</url> </snapshotRepository>--> </distributionManagement>
一般來說,分發構件到遠程倉庫需要認證,如果你沒有配置任何認證信息,你往往會得到401錯誤。這個時候,如下在settings.xml中配置認證信息:
< repository >節點下的< id >對應setting.xml文件中的server的id
需要注意的是,settings.xml中server元素下id的值必須與POM中repository或snapshotRepository下id的值完全一致。將認證信息放到settings下而非POM中,是因爲POM往往是它人可見的,而settings.xml是本地的。
<!--maven連接nexus需要驗證用戶名和密碼-->
<settings>
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
</settings>
mvn deploy 用來將項目生成的構件分發到遠程Maven倉庫。