解決,MAVEN - deploy - admin用戶4xx權限問題

  • eclipse中指定的 setting.xml

<?xml version="1.0" encoding="utf-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <!--本地倉庫位置-->
    <localRepository>D:/.m2/repository</localRepository>
    <offline>false</offline>
    <pluginGroups />
    <proxies />
    <!--設置 Nexus 認證信息 -->
    <servers>
		<server>
        	<id>releases</id>
        	<username>admin</username>
        	<password>xyz</password>
    	</server>
		<server>
        	<id>snapshots</id>
        	<username>admin</username>
        	<password>xyz</password>
    	</server>
    </servers>
</settings>
  • pom.xml
	<!-- snapshots/releases發佈配置 -->
	<distributionManagement>
		<repository>
			<id>releases</id>
			<url>http://192.168.9.119:8081/nexus/content/repositories/releases</url>
		</repository>
		<snapshotRepository>
			<id>snapshots</id>
			<url>http://192.168.9.119:8081/nexus/content/repositories/snapshots/</url>
		</snapshotRepository>
	</distributionManagement>
  • 上面的配置是沒任何問題。
  • admin權限是夠的
  • 配置沒出任何問題

  • 報錯信息
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.388 s
[INFO] Finished at: 2018-11-07T11:24:04+08:00
[INFO] Final Memory: 32M/211M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project eqzh-admin-core: Failed to deploy a
rtifacts: Could not transfer artifact com.eqzh.admin:eqzh-admin-core:jar:1.0-20181107.032404-2 from/to snapshots (http://192.168.9.119:8081/nexus/cont
ent/repositories/snapshots/): Failed to transfer file: http://192.168.9.119:8081/nexus/content/repositories/snapshots/com/eqzh/admin/eqzh-admin-core/1
.0-SNAPSHOT/eqzh-admin-core-1.0-20181107.032404-2.jar. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy
) on project eqzh-admin-core: Failed to deploy artifacts: Could not transfer artifact com.eqzh.admin:eqzh-admin-core:jar:1.0-20181107.032404-2 from/to
 snapshots (http://192.168.9.119:8081/nexus/content/repositories/snapshots/): Failed to transfer file: http://192.168.9.119:8081/nexus/content/reposit
ories/snapshots/com/eqzh/admin/eqzh-admin-core/1.0-SNAPSHOT/eqzh-admin-core-1.0-20181107.032404-2.jar. Return code is: 401, ReasonPhrase: Unauthorized
.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)

關鍵來了

  • deploy.bat
call mvn deploy -X -Dmaven.test.skip=true
call pause

這個腳本命令本身並沒有問題,問題出在對MAVEN機制不熟悉。

cmd 中調用 mvn 命令時,MAVEN默認啓用的順序

${MAVEN_HOME}/conf/settings.xml      # MAVEN默認全局配置
${user.home}/.m2/settings.xml        # 用戶配置
                      # 優先級:用戶配置 > MAVEN默認全局配置

這個路徑下的setting.xml的配置文件,而不是在ide裏指定的setting.xml的配置文件

所以,在使用腳本進行MAVEN操作時,請指定你需要使用的setting.xml文件路徑,所以

正確的deploy.bat配置

call mvn deploy -X -Dmaven.test.skip=true --settings D:\.m2\settings.xml
call pause

另外值得注意的是

  • 在eclipse中構建,打包,發佈項目時,請使用 Run as --> Maven biuld 來進行MAVEN操作,因爲eclipse會爲你直接指定,你在eclipse中配置的setting.xml文件路徑作爲--settings的參數。
  • 如圖
    在這裏插入圖片描述
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章