解决,MAVEN - deploy - admin用户4xx权限问题

  • eclipse中指定的 setting.xml



    
    D:/.m2/repository
    false
    
    
    
    
		
        	releases
        	admin
        	xyz
    	
		
        	snapshots
        	admin
        	xyz
    	
    

  • pom.xml
	
	
		
			releases
			http://192.168.9.119:8081/nexus/content/repositories/releases
		
		
			snapshots
			http://192.168.9.119:8081/nexus/content/repositories/snapshots/
		
	
  • 上面的配置是没任何问题。
  • 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的参数。
  • 如图
    解决,MAVEN - deploy - admin用户4xx权限问题_第1张图片

你可能感兴趣的:(配置文件)