【問題解決】mvn deploy出現401錯誤

mvn deploy出現401錯誤

mvn deploy出現401錯誤

問題

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on p
roject panda-config: Failed to deploy artifacts: Could not transfer artifact top.alanlee:panda-config:jar:1.0.
0-20200223.035607-1 from/to nexus-snapshots (http://xxx.xxx.245.65:8081/repository/maven-snapshots/): Failed t
o transfer file http://xxx.xxx.245.65:8081/repository/maven-snapshots/top/alanlee/panda-config/1.0.0-SNAPSHOT/
panda-config-1.0.0-20200223.035607-1.jar with status code 401 -> [Help 1]

原因

一般報401這個錯,是因爲沒有權限,沒權限的話,大部分都是因爲密碼錯了導致,或者這個賬號本身就沒有傳jar的權限,一般是maven目錄conf的setting.xml裏沒有配置認證,查看maven的config路徑下的settings.xml,查看是否設置了用戶名和密碼。

解決

在.m2/settings.xml中的server節點下設置用戶名和密碼。

<server>
  <id>nexus-releases</id>
  <username>admin</username>
  <password>密碼</password>
</server>

<server>
  <id>nexus-snapshots</id>
  <username>admin</username>
  <password>密碼</password>
</server>

在pom.xml文件中添加

<distributionManagement>
    <repository>
        <id>nexus-releases</id>
        <name>Nexus Release Repository</name>
        <url>http://ip:8081/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>nexus-snapshots</id>
        <name>Nexus Snapshot Repository</name>
        <url>http://ip:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>

重新執行mvn deploy

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