nexus3 Unauthorized問題解決

環境

Nexus3 version : 3.20.1-01

問題

nexus3 在安裝完後通過mvn deploy命令,出行“Return code is: 401, ReasonPhrase: Unauthorized.”異常。

分析解決

1、maven setting.xml配置:

	  <server>  
	    <id>maven-releases</id>  
	    <username>deployment</username>  
	    <password>deployment</password>  
	  </server>  
	  <server>  
	    <id>maven-snapshots</id>  
	    <username>deployment</username>  
	    <password>deployment</password>  
	  </server> 

2、測試應用工程pom.xml中配置

	<distributionManagement>
		<repository>
			<id>nexus</id>
			<name>maven-releases</name>
			<url>http://192.168.1.8:8081/repository/maven-releases/</url>
		</repository>
		<snapshotRepository>
			<id>nexus</id>
			<name>maven-snapshots</name>
			<url>http://192.168.1.8:8081/repository/maven-snapshots/</url>
		</snapshotRepository>
	</distributionManagement>

     首先,檢查了用戶名和密碼,沒有發現有問題,檢查了請求路徑,也沒有發現有問題。在網上搜索了很多類似問題的解決辦法,都沒有找到問題所在。

     通過對比發現pom 文件中distributionManagement中配置的repository 配置的id與setting.xml配置的id不一致,一個是maven-releases, 一個是nexus。修改成一致後,問題解決。這個配置還是從網上拷貝過來的,release和snapshot的倉庫id都是一樣的,看來網上拷貝過來的東西還是要仔細檢查一下。

    <distributionManagement>
        <repository>
            <id>nexus</id>
            <name>maven-releases</name>
            <url>http://192.168.1.8:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus</id>
            <name>maven-snapshots</name>
            <url>http://192.168.1.8:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

      對應的正確的配置爲:

	<distributionManagement>
		<repository>
			<id>maven-releases</id>
			<name>maven-releases</name>
			<url>http://192.168.1.8:8081/repository/maven-releases/</url>
		</repository>
		<snapshotRepository>
			<id>maven-snapshots</id>
			<name>maven-snapshots</name>
			<url>http://192.168.1.8:8081/repository/maven-snapshots/</url>
		</snapshotRepository>
	</distributionManagement>

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章