我想在远程服务器上使用maven部署我的应用程序,以便拥有一个持续集成系统:)。
我已经检查了stackoverflow上的许多问题,但无法使其正常工作。首先,我将向您展示我的错误,然后是我所做的配置。
这里有关于上传的消息,似乎是正确的:
Uploaded: http://SERVEUR_IP/manager/text/deploy?path=%2FGiveMeAShow (49631 KB at 51.5 KB/sec)
错误:
[ERROR] Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project GiveMeAShow: Tomcat return http status error: 401, Reason Phrase: Unauthorized:
[ERROR] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
[ERROR] <html>
[ERROR] <head>
[ERROR] <title>401 Unauthorized</title>
[ERROR] <style type="text/css">
[ERROR] <!--
[ERROR] BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;font-size:12px;}
[ERROR] H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}
[ERROR] PRE, TT {border: 1px dotted #525D76}
[ERROR] A {color : black;}A.name {color : black;}
[ERROR] -->
[ERROR] </style>
[ERROR] </head>
[ERROR] <body>
[ERROR] <h1>401 Unauthorized</h1>
[ERROR] <p>
[ERROR] You are not authorized to view this page. If you have not changed
[ERROR] any configuration files, please examine the file
[ERROR] <tt>conf/tomcat-users.xml</tt> in your installation. That
[ERROR] file must contain the credentials to let you use this webapp.
[ERROR] </p>
[ERROR] <p>
[ERROR] For example, to add the <tt>manager-gui</tt> role to a user named
[ERROR] <tt>tomcat</tt> with a password of <tt>s3cret</tt>, add the following to the
[ERROR] config file listed above.
[ERROR] </p>
[ERROR] <pre>
[ERROR] <role rolename="manager-gui"/>
[ERROR] <user username="tomcat" password="s3cret" roles="manager-gui"/>
[ERROR] </pre>
[ERROR] <p>
[ERROR] Note that for Tomcat 7 onwards, the roles required to use the manager
[ERROR] application were changed from the single <tt>manager</tt> role to the
[ERROR] following four roles. You will need to assign the role(s) required for
[ERROR] the functionality you wish to access.
[ERROR] </p>
[ERROR] <ul>
[ERROR] <li><tt>manager-gui</tt> - allows access to the HTML GUI and the status
[ERROR] pages</li>
[ERROR] <li><tt>manager-script</tt> - allows access to the text interface and the
[ERROR] status pages</li>
[ERROR] <li><tt>manager-jmx</tt> - allows access to the JMX proxy and the status
[ERROR] pages</li>
[ERROR] <li><tt>manager-status</tt> - allows access to the status pages only</li>
[ERROR] </ul>
[ERROR] <p>
[ERROR] The HTML interface is protected against CSRF but the text and JMX interfaces
[ERROR] are not. To maintain the CSRF protection:
[ERROR] </p>
[ERROR] <ul>
[ERROR] <li>Users with the <tt>manager-gui</tt> role should not be granted either
[ERROR] the <tt>manager-script</tt> or <tt>manager-jmx</tt> roles.</li>
[ERROR] <li>If the text or jmx interfaces are accessed through a browser (e.g. for
[ERROR] testing since these interfaces are intended for tools not humans) then
[ERROR] the browser must be closed afterwards to terminate the session.</li>
[ERROR] </ul>
[ERROR] <p>
[ERROR] For more information - please see the
[ERROR] <a href="/docs/manager-howto.html">Manager App HOW-TO</a>.
[ERROR] </p>
[ERROR] </body>
[ERROR]
[ERROR] </html>
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
看起来很清楚,这是一个授权问题。让我们看看我的远程tomcat7 tomcat-users.xml文件:
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<role rolename="manager-script"/>
<role rolename="admin-script"/>
<user username="admin" password="password" roles="manager-gui,manager-script,admin-gui,admin-script" />
</tomcat-users>
我知道我不应该授予所有角色,但是嘿它没有用,所以我尝试了:)。
我可以在我的浏览器中使用&#34; admin&#34;通过HTTP登录app manager / admin页面和#34;密码&#34;。我认为这很好。
这是我在maven-tomcat-plugin中的配置:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<usernamee>admin</usernamee>
<password>password</password>
<url>http:SERVEUR_IP/manager/text</url>
<server>TomcatServer</server>
<path>/GiveMeAShow</path>
</configuration>
</plugin>
当我开始尝试时,我无法上传war文件。添加这个允许我这样做。但似乎授权问题会在稍后出现。
我还在~/.m2/settings.xml
的远程服务器中放了一个settings.xml文件:
<?xml version='1.0' encoding='utf-8'?>
<servers>
<server>
<id>TomcatServer</id>
<username>admin</username>
<password>password</password>
</server>
</servers>
~/.m2
文件夹只包含一个子文件夹和我创建的文件。
请注意,我使用root用户执行所有这些操作。
我现在不知道该尝试什么,谢谢你的帮助!
修改
我确实喜欢@fatteddy说:
- 创建仅部署用户。仅使用角色&#34; manager-script&#34;
- 更正了我在pom.xml中的错误,将<usernamee>
更改为</username>
我认为创建一个仅限部署的用户可以完成大部分工作,因为我在TRAVIS-CI上同时测试<username>
标签中的env变量而没有错误。
答案 0 :(得分:2)
实际上这是一个身份验证问题。
尝试定义(显然是出于安全原因)一个单独的部署用户,其中分配了manager-script
(仅此一个)角色。别忘了重启tomcat。
如果这无助于更改tomcat管理器URL的路径段(manager/
,manager
,manager/text
,manager/text/
- &gt;的组合,就我而言可以记住,在以后的tomcat版本中已经修复了尾随斜杠的问题。
答案 1 :(得分:0)
我忘了做的最简单的事情是 - 在设置更改后重启Tomcat。这句话 - &#34;别忘了重启tomcat&#34;帮了很多忙! :)