天天看點

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>