【问题标题】:maven tomcat7 deploymaven tomcat7 部署
【发布时间】:2011-11-22 23:40:29
【问题描述】:

POM.xml:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>tomcat-maven-plugin</artifactId>
    <configuration>
        <url>http://localhost:8080/manager/html</url>
        <server>myserver</server>
        <path>/test</path>
        <warFile>${project.build.directory}/${project.build.finalName}.war</warFile>
    </configuration>
</plugin>

使用的 Eclipse: 带有 m2e 插件的 Eclipse indigo 3.7

修改 Tomcat7/conf/tomcat-users.xml

 <role rolename="admin"/>
  <role rolename="manager"/>
  <user username="admin" password="admin" roles="admin,manager"/>
</tomcat-users>

Context.xml Tomcat7/conf/context.xml,将&lt;context&gt;改为

<Context antiJARLocking="true" antiResourceLocking="true">

apache-maven\conf\settings.xml

在服务器标签下添加以下条目:

  <servers>
    <server>
    <id>myserver</id>
    <username>admin</username>
    <password>admin</password>
    </server>

启动 tomcat 服务器

target 运行:tomcat:deploytomcat:undeploy

出现以下错误:

[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:redeploy (default-cli) on project test: Cannot invoke Tomcat manager: Server returned HTTP response code: 403 for URL: http://localhost:8080/manager/html/deploy?path=%2Ftest&war=&update=true -> [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

项目名称:测试

war 文件名:test-1.0-SNAPSHOT.war

发现了类似的问题,但没有得到太多用处:Tomcat-maven-plugin 401 error

tomcat-maven-plugin 403 error

【问题讨论】:

  • 当您访问此 URL:http://localhost:8080/manager/html 时是否加载了页面?

标签: eclipse tomcat maven


【解决方案1】:

manager-gui 添加到角色中:

<user username="admin" password="admin" roles="admin,manager,manager-gui" />

然后重启 Tomcat。

确保您的 XML 配置文件正在使用中。一个简单的方法是在其中写入一个未关闭的标签并检查错误消息。如果您没有收到任何错误消息,则说明您使用未使用的 XML 编写。

【讨论】:

  • 在做 Manager-gui 角色后,出现以下错误:无法在项目测试中执行目标 org.codehaus.mojo:tomcat-maven-plugin:1.1:redeploy (default-cli):无法调用 Tomcat manager: FAIL - 上下文 /test 在 server.xml 中定义,可能无法取消部署 [ERROR] FAIL - Application already exists at path /test
  • server.xml 中删除&lt;Context path="/test" ... 标签并从Tomcat 的webapp 目录中删除test.wartest 目录,然后再次尝试mvn tomcat:redeploy
  • 当我这样做时,应用程序工作正常。但是,如果我执行 -mvn clean 我修改过的所有与服务器相关的 xml 文件(即 context.xml、server.xml、tomcat-users.xml),文件将被监听并替换为原始文件。为什么会这样?
  • 我通常用bin/startup.bat从命令行启动Tomcat。我发现这种方式比从 Eclipse 启动 Tomcat 更可靠。
【解决方案2】:

在tomcat 7中你应该设置

<user username="admin" password="admin" roles="manager-script,manager-gui" />  

使用 maven 插件部署

【讨论】:

  • 非常非常非常非常感谢你,伙计。我一直在努力让它工作几个小时。每次我尝试部署并添加 manager-script 时都会收到 403 错误。
【解决方案3】:

虽然回答迟了,但有人可能会觉得这很有用。 如果您使用的是 maven3 和 tomcat7。下面的方法对我有用。我不知道 tomcat7 中应用程序管理器端点的变化。

Environment - Apache Maven 3.0.4,apache-tomcat-7.0.34,Windows 7

Tomcat7 已将其部署端点从 http://tomcatserver:8080/manager/html 更改为 http://tomcatserver:8080/manager/text

所以我的 pom.xml 将是

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>tomcat-maven-plugin</artifactId>
     <configuration>
           <url>http://tomcatserver:8080/manager/text</url>
           <server>tomcat</server>
          <path>/myWebApp</path>
         </configuration>
  </plugin>

在 tomcat-users.xml 中

<role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <role rolename="manager-jmx"/>
  <role rolename="manager-status"/>
  <role rolename="admin-gui"/>
  <role rolename="admin-script"/>

  <user username="root" password="root" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>

在 maven settings.xml 中

<server>
  <id>tomcat</id>
  <username>root</username>
  <password>root</password>
</server>

在 context.xml 中,虽然这是可选的,并且与 maven3 部署到 tomcat7 无关,但有时可能会发生 jar 锁定,所以为了更安全。

<Context  antiJARLocking="true" antiResourceLocking="true">

现在发布

mvn tomcat:deploy

记得在部署maven之前启动tomcat。

如果部署成功,您的应用程序将在

http://tomcatserver:8080/myWebApp

【讨论】:

    【解决方案4】:

    对于 tomcat 7,您使用了错误的目标。尝试使用 tomcat7:deploy 和 tomcat7:undeploy。

    【讨论】:

      【解决方案5】:

      在提到的网站上找到快速解决方案...

      http://www.avajava.com/tutorials/lessons/how-do-i-deploy-a-maven-web-application-to-tomcat.html

      在 Eclipse 和 Sprint 测试套件中按预期工作

      注意:- 我使用了干净的 tomcat:deploy,对我来说效果很好。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-10-26
        • 2013-12-03
        • 1970-01-01
        • 1970-01-01
        • 2013-06-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多