eclipse - maven tomcat7部署

标签 eclipse tomcat maven

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>

上下文.xml Tomcat7/conf/context.xml,更改<context>

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

apache-maven\conf\settings.xml

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

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

启动tomcat服务器

目标 运行: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

最佳答案

虽然回答晚了,但有人可能会觉得这很有用。 如果您使用的是 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

关于eclipse - maven tomcat7部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7517808/

相关文章:

java - 在 Eclipse 中使用多个 OSGi 包

tomcat - 使用 grails flash 对象和负载平衡

java - 无法使用 JavaMail API 编译 JSP 文件

Maven:在一个阶段将一个插件的多个执行与其他插件执行交错

java - 无法创建请求的服务[org.hibernate .engine.jdbc.env.spi.JdbcEnvironment]-MySQL

java - 为什么m2eclipse从Eclipse构建路径中排除资源?

java - 类型不匹配 : cannot convert from Set<Object> to Set<Long>

java - 如何测量 Java 代码库中的测试密度?

java - 即使使用 JavascriptExecutor 滚动也无法点击元素

java - 在外部 Tomcat 中部署 war 时,Springboot 端点失败