原文出处: http://www.javatang.com/archives/2010/01/23/4518375.html
原文出处: http://cloudera.iteye.com/blog/781160
怎样使用deploy命令部署构件到nexus服务器上可以参考经典的《Maven Definitive Guide》(Maven操作指南),书中的16.7节里面讲解的非常详细。假设我们在项目pom.xml文件中对maven服务器的设置信息如下:
1.<distributionManagement>
2. <repository>
3. <id>nexus-releases</id>
4. <name>Local Nexus Repository</name>
5. <url>http://192.168.1.99:8081/content/repositories/releases</url>
6. </repository>
7. <snapshotRepository>
8. <id>nexus-snapshots</id>
9. <name>Local Nexus Repository</name>
10. <url>http://192.168.1.99:8081/content/repositories/snapshots</url>
11. </snapshotRepository>
12. </distributionManagement>
里我要说的是在使用的过程中遇到的几个都是“Failed to transfer file”错误,错误信息如下格式:
rror deploying artifact: Failed to transfer file:… Return code is:4xx
就是说前面错误的信息都是一样的,只是后面返回的HTTP状态数字不同。
. Return code is: 405
这个问题害我查了两个多小时才发现错误的根源,简单的错误就是在Maven执行到上传文件到服务器的时候出现一个HTTP 405错误。开始的时候总以为是Maven本身的问题,所以在这个上面浪费了不少时间。后来仔细查了405错误的含义是“用来访问本页面的 HTTP 方法不被允许”,最后终于发现是因为前面repository的地址写错了,或者是端口写错,或者是地址中的某个单词拼错了,反正原因就是repository的地址写错了。
. Return code is: 401或者Return code is: 403
其实403错误就是“禁止访问”的含义,所以问题的根源肯定在授权上面。Maven在默认情况下会使用deployment帐号(默认密码deploy)登录的系统,但是关键的Nexus中Releases仓库默认的Deployment Policy是“Disable Redeploy”,所以无法部署的问题在这个地方,方法是将其修改为“Allow Redeploy”就可以了。
这里还没有结束,因为如果直接按照上面的设置的话会有一个安全问题,那就是这样所有的开发人员都可以将构件部署到Nexus的releases仓库中了,时间长了会导致这个仓库中非常乱,这也应该是nexus为什么默认情况下将Release仓库的发布权限关闭的原因了。解决这个问题的整体思路就是在部署构件的时候需要使用用户名和密码登录,操作如下:
(1) 首先将Releases仓库默认的Deployment Policy修改为“Allow Redeploy”;
(2) 然后在右边的Security下面的Users中,修改deployment帐号的密码,方法是在帐号上右键,然后选择“Set Password”(PS:这个操作我找了好久,后来无意中右键才找到,呵呵~~);
(3) 这个时候如果直接执行 mvn deploy 命令的话就又会出现401错误,还有一步就是将密码设置到Maven settings.xml中。打开settings.xml文件(${user.home}/.m/settings.xml或%{m2_home}/conf/settings.xml),找到<servers>,然后修改信息如下:
1.<server>
2. <id>releases</id>
3. <username>deployment</username>
4. <password>deploydv89</password>
5. </server>
6.
7. <server>
8. <id>snapshots</id>
9. <username>deployment</username>
10. <password>deploydv89</password>
11. </server>
里需要特别说明一句的是里面的id必须和你在项目pom.xml文件中distributionManagement下面设置的仓库id一致!当然了,这个里面你也可以设置admin帐号,或者参照deployment的权限手动添加新的帐号等等都是可以的。
然,问题到这里已经得到了比较完美的解放,但是如果有人还要较真的话会想到帐号的密码直接放到配置文件里面不是很安全。其实只要这里不建议放admin帐号,而deployment是无法登录的。如果非要更安全一些的话,也可以使用Maven 2.1.0之后所提供的密码加密功能,操作的步骤如下:
(1) 使用“mvn –encrypt-master-password xxx”或“mvn –emp xxx”创建一个主密钥,后面的xxx就是你所要设置的密钥的内容,这个密钥主要用于后面加密密码来用的;命令执行之后会产生一个类似{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}形式的字符串。
(2) 在${user.home}/.m/目录下创建一个名为settings-security.xml文件,我们将刚刚产生的主密钥放到这个文件中,文件的内容如下:
1.<?xml version="1.0" encoding="UTF-8"?>
2.<settingsSecurity>
3. <master>{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}</master>
4.</settingsSecurity>
意,这个settings-security.xml文件一定要放在${user.home}/.m/目录下面,而不能放在${m2_home}/conf目录下!
(3) 使用“mvn –encrypt-password xxx”或“mvn –ep xxx”命令对帐号的密码进行加密,后面的xxx就是帐号的密码,加密之后依然会产生一个“{xxx}”形式的字符串,将这个字符串替换上面settings.xml文件中的server下面的password节点内容即可。
还有一种更安全的方式,就是将主密钥放到U盘里面,具体的操作可以看下面的参考资料。
. Return code is: 400
400错误的含义是“错误的请求”,在这里的原因是往往是没有部署到nexus的仓库中。nexus的repository分三种类型:Hosted、Proxy和Virtual,另外还有一个repository group(仓库组)用于对多个仓库进行组合。部署的时候只能部署到Hosted类型的仓库中,如果是其他类型就会出现这个400错误。
有一种情况也会出现400错误,就是默认情况下部署构件到Releases仓库中有时也会出现400错误,这个原因就像上面提到的那样,Nexus中Releases仓库默认的Deployment Policy是“Disable Redeploy”,所以无论你在settings.xml文件中将server的username设置为deployment还是使用admin都是无法部署的,就会出现这个400错误。这个问题也困扰了我好长时间,而且我还看到网上有人说admin没有部署构件的权限,这个是不对的。修改的方法可以参考上面第2条的做法。
分享到:
相关推荐
信息: Deploying web application ...严重: Context [/blog] startup failed due to previous errors ApplicationFilterConfig[name=EncodingFilter, filterClass=com.v512.guestbook.web.CharacterEncodingFilter]
Author: Graham Dumpleton ISBN-10: 9781491957165 Year: 2018 Pages: 162 Language: ...This book is a perfect follow-up to OpenShift for Developers: A Guide for Impatient Beginners (O’Reilly).
java.awt.datatransfer 提供在应用程序之间和在应用程序内部传输数据的接口和类。 java.awt.dnd Drag 和 Drop 是一种直接操作动作,在许多图形用户界面系统中都会遇到它,它提供了一种机制,能够在两个与 GUI 中...
Deploying to OpenShift A Guide for Busy Developers 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
Beginning iOS Programming: Building and Deploying iOS Applications starts at the beginning—including an introduction to Objective C—and gives you the skills you need to get your apps up and running...
Deploying with JRuby: Deliver Scalable Web Apps using the JVM
Deploying SharePoint 2016: Best Practices for Installing, Configuring, and Maintaining SharePoint Server 2016 This book shows you how to install, configure, and maintain the latest release of ...
Machine Trading is a practical guide to building your algorithmic trading business. Written by a recognized trader with major institution expertise, this book provides step-by-step instruction on ...
cisco ipv6 branch network deploying
Deploying Rails with Docker, Kubernetes and ECS shows you how to set up the project, push it to DockerHub, manage services and set up an efficient continuous integration environment. Every concept is ...
Jim is the author of more than a dozen books, including Deploying Voice over Wireless LANs (Cisco Press), Wireless Networks: First Step (Cisco Press), Implementing 802.1X Security Solutions (Wiley), ...
For security professionals needing to get up and running fast with the topic of RFID, this How to Cheat approach to the topic is the perfect "just what you need to know" book! * For most business ...
Node.js is a popular choice for teams that need to design, build, test, deploy, maintain, and monitor large-scale distributed systems. Starting with a detailed overview of the Node.js architecture, ...
微服务从设计到部署的英文原版:Microservices Designing Deploying
Deploying.NET.Applications.Learning.MSBuild.and.ClickOnce.2006.pdf
NULL 博文链接:https://wuhuizhong.iteye.com/blog/1275320
Eclipse Rich Ajax Platform: Bringing Rich Client to the Web Paperback: 148 pages Publisher: Apress; 1 edition (December 29, 2008) Language: English ISBN-10: 1430218835 ISBN-13: 978-1430218838 ...
DGNLib is a small C/C++ library for reading and writing DGN files. Where can I get the source code? dgnlib-1.11.zip: Current standalone source with dgndump example mainline. Does DGNLib support all ...
该文档给出了tomcat的安装及环境配置及在环境配置中出现的常见问题的解答
Cisco - Deploying Voice over Wireless LANs.chm Copyright About the Author Acknowledgments Icons Used in This Book Command Syntax Conventions Introduction Part I: Fundamental Elements Chapter ...