Java 如何使用Maven将WAR部署到Tomcat7服务器?
下面给出了一个Java 如何使用Maven将WAR部署到Tomcat7服务器?,java,maven,tomcat,tomcat7,maven-3,Java,Maven,Tomcat,Tomcat7,Maven 3,下面给出了一个pom.xml 运行mvn tomcat:deploy时,出现以下错误: Uploading: http://AAA.BBB.CCC.DDD:8080/manager/text/deploy?path=%2Fmyapp Uploaded: http://AAA.BBB.CCC.DDD:8080/manager/text/deploy?path=%2Fmyapp (9553 KB at 137.0 KB/sec) [INFO] tomcatManager status code:4
pom.xml
运行mvn tomcat:deploy
时,出现以下错误:
Uploading: http://AAA.BBB.CCC.DDD:8080/manager/text/deploy?path=%2Fmyapp
Uploaded: http://AAA.BBB.CCC.DDD:8080/manager/text/deploy?path=%2Fmyapp (9553 KB at
137.0 KB/sec)
[INFO] tomcatManager status code:403, ReasonPhrase:Forbidden
[INFO] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/h
tml4/strict.dtd">
[INFO] <html>
[INFO] <head>
[INFO] <title>403 Access Denied</title>
[INFO] <style type="text/css">
[INFO] <!--
[INFO] BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-colo
r:white;font-size:12px;}
[INFO] H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:
#525D76;font-size:22px;}
[INFO] PRE, TT {border: 1px dotted #525D76}
[INFO] A {color : black;}A.name {color : black;}
[INFO] -->
[INFO] </style>
[INFO] </head>
[INFO] <body>
[INFO] <h1>403 Access Denied</h1>
[INFO] <p>
[INFO] You are not authorized to view this page.
[INFO] </p>
[INFO] <p>
[INFO] If you have already configured the Manager application to allow acces
s and
[INFO] you have used your browsers back button, used a saved book-mark or si
milar
[INFO] then you may have triggered the cross-site request forgery (CSRF) pro
tection
[INFO] that has been enabled for the HTML interface of the Manager applicati
on. You
[INFO] will need to reset this protection by returning to the
[INFO] <a href="/manager/html">main Manager page</a>. Once you
[INFO] return to this page, you will be able to continue using the Manager
[INFO] appliction's HTML interface normally. If you continue to see this acc
ess
[INFO] denied message, check that you have the necessary permissions to acce
ss this
[INFO] application.
[INFO] </p>
[INFO] <p>
[INFO] If you have not changed
[INFO] any configuration files, please examine the file
[INFO] <tt>conf/tomcat-users.xml</tt> in your installation. That
[INFO] file must contain the credentials to let you use this webapp.
[INFO] </p>
[INFO] <p>
[INFO] For example, to add the <tt>manager-gui</tt> role to a user named
[INFO] <tt>tomcat</tt> with a password of <tt>s3cret</tt>, add the following
to the
[INFO] config file listed above.
[INFO] </p>
[INFO] <pre>
[INFO] <role rolename="manager-gui"/>
[INFO] <user username="tomcat" password="s3cret" roles="manager-gui"/>
[INFO] </pre>
[INFO] <p>
[INFO] Note that for Tomcat 7 onwards, the roles required to use the manager
[INFO] application were changed from the single <tt>manager</tt> role to the
[INFO] following four roles. You will need to assign the role(s) required fo
r
[INFO] the functionality you wish to access.
[INFO] </p>
[INFO] <ul>
[INFO] <li><tt>manager-gui</tt> - allows access to the HTML GUI and the st
atus
[INFO] pages</li>
[INFO] <li><tt>manager-script</tt> - allows access to the text interface a
nd the
[INFO] status pages</li>
[INFO] <li><tt>manager-jmx</tt> - allows access to the JMX proxy and the s
tatus
[INFO] pages</li>
[INFO] <li><tt>manager-status</tt> - allows access to the status pages onl
y</li>
[INFO] </ul>
[INFO] <p>
[INFO] The HTML interface is protected against CSRF but the text and JMX int
erfaces
[INFO] are not. To maintain the CSRF protection:
[INFO] </p>
[INFO] <ul>
[INFO] <li>Users with the <tt>manager-gui</tt> role should not be granted ei
ther
[INFO] the <tt>manager-script</tt> or <tt>manager-jmx</tt> roles.</li>
[INFO] <li>If the text or jmx interfaces are accessed through a browser (e.g
. for
[INFO] testing since these interfaces are intended for tools not humans)
then
[INFO] the browser must be closed afterwards to terminate the session.</
li>
[INFO] </ul>
[INFO] <p>
[INFO] For more information - please see the
[INFO] <a href="/docs/manager-howto.html">Manager App HOW-TO</a>.
[INFO] </p>
[INFO] </body>
[INFO] </html>
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:14.595s
[INFO] Finished at: Wed Apr 16 00:14:08 MSD 2014
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------
tomcat用户.xml
:
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<tomcat-users>
<!--
NOTE: By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application. If you wish to use this app,
you must define such a user - the username and password are arbitrary.
-->
<!--
NOTE: The sample user and role entries below are wrapped in a comment
and thus are ignored when reading this file. Do not forget to remove
<!.. ..> that surrounds them.
-->
<!--
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
-->
<role rolename="manager"/>
<role rolename="manager-gui"/>
<user username="admin" password="..." rol
es="manager-gui,manager"/>
</tomcat-users>
<settings>
<servers>
<server>
<id>myapp-1</id>
<username>admin</username>
<password>...</password>
</server>
</servers>
</settings>
<role rolename="manager-gui"/>
<role rolename="tomcat"/>
<role rolename="manager-script"/>
<role rolename="manager-status"/>
<role rolename="manager-jmx"/>
<user username="admin" password="..." roles="tomcat,manager-gui,manager-script,manager-jmx,manager-status"/>
您应该使用“tomcat7:deploy”而不是“tomcat:deploy”。它们实际上并不相同。我通过
tomcat users.xml
)
然后运行
mvn cargo:deploy
当设置中提供的
时,我遇到了403禁止。xml
指定了管理器gui
角色,但没有在conf/tomcat users.xml中指定管理器脚本
角色
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.remote.username>...</cargo.remote.username>
<cargo.remote.password>...</cargo.remote.password>
<cargo.hostname>...</cargo.hostname>
<cargo.protocol>http</cargo.protocol>
<cargo.servlet.port>8080</cargo.servlet.port>
</properties>
</configuration>
<!-- Deployer configuration -->
<deployer>
<type>remote</type>
</deployer>
<deployables>
<deployable>
<groupId>...</groupId>
<artifactId>...</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
</plugin>
管理器gui
角色足以通过浏览器登录到tomcat管理器。但是需要管理器脚本
角色以编程方式上载war
请参阅
•管理器gui-访问HTML界面
•管理者状态-仅访问“服务器状态”页面
•管理器脚本-访问本文档中描述的工具友好的纯文本界面和“服务器状态”页面
•manager jmx-访问jmx代理接口和“服务器状态”页面
注意
•建议不要将manager脚本或manager jmx角色授予具有manager gui角色的用户
我尝试了这个(mvn tomcat7:deploy
),但它也产生了403拒绝访问
错误。您是否查看了我在Tomcat端的权限(我分配给用户的角色,我尝试使用这些角色部署WAR)?他们还好吗?
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.remote.username>...</cargo.remote.username>
<cargo.remote.password>...</cargo.remote.password>
<cargo.hostname>...</cargo.hostname>
<cargo.protocol>http</cargo.protocol>
<cargo.servlet.port>8080</cargo.servlet.port>
</properties>
</configuration>
<!-- Deployer configuration -->
<deployer>
<type>remote</type>
</deployer>
<deployables>
<deployable>
<groupId>...</groupId>
<artifactId>...</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
</plugin>