Tomcat 8 与 Maven 的集成

2022-09-03 01:57:29

听起来Eclipse(开普勒)没有适合Tomcat 8的插件。我想将我的.war部署到Tomcat 8中,并通过Maven pom.xml文件运行它。任何人都可以为我提供分步指导或任何资源吗?

我的 POM 文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Test-App</groupId>
  <artifactId>test-rest</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>test-rest Maven Webapp</name>
  <url>http://maven.apache.org</url>
     <!-- Tomcat plugin -->


  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
  <plugins>
  <plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
     <path>/${project.build.finalName}</path>
     <update>true</update>
     <url>http:// localhost:8080/manager/text</url>
     <username>tomcat</username>
     <password>tomcatuser</password>
    </configuration>
   </plugin>
   </plugins>
    <finalName>test-rest</finalName>
  </build>
</project>

答案 1

你可以使用货物pluygin代替,这对我有用,部署到tomcat8:

             <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>1.4.8</version>
                <configuration>
                    <container>
                        <containerId>tomcat8x</containerId>
                        <home>${env.CATALINA_HOME}</home>
                    </container>
                    <configuration>
                        <type>existing</type>
                        <home>${env.CATALINA_HOME}</home>
                    </configuration>
                    <deployables>
                        <deployable>
                            <groupId>com.yourcompany</groupId>
                            <artifactId>ROOT</artifactId>
                            <type>war</type>
                            <properties>
                                <context>${project.build.finalName}</context>
                            </properties>
                        </deployable>
                    </deployables>
                    <deployer>
                        <type>installed</type>
                    </deployer>
                </configuration>
            </plugin>

答案 2

如何用 cargo 和 tomcat8 进行战争的例子

mvn clean verify org.codehaus.cargo:cargo-maven2-plugin:run -Dcargo.maven.containerId=tomcat8x -Dcargo.maven.containerUrl=http://repo1.maven.org/maven2/org/apache/tomcat/tomcat/8.5.9/tomcat-8.5.9.zip

如果你想把它添加到你的pom

<plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <version>${cargo.version}</version>
  <configuration>
    <container>
      <containerId>tomcat8x</containerId>
      <zipUrlInstaller>
          <url>http://repo1.maven.org/maven2/org/apache/tomcat/tomcat/8.5.9/tomcat-8.5.9.zip</url>
      </zipUrlInstaller>
    </container>
  </configuration>
</plugin>

然后运行你的战争(如果你的pom是一场战争)

mvn cargo:run

使用调试运行(不需要内存选项)

<plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <version>${cargo.version}</version>
  <configuration>
    <container>
      <containerId>tomcat8x</containerId>
      <zipUrlInstaller>
          <url>http://repo1.maven.org/maven2/org/apache/tomcat/tomcat/8.5.9/tomcat-8.5.9.zip</url>
      </zipUrlInstaller>
    </container>
    <configuration>
      <properties>
        <!-- <cargo.servlet.port>8200</cargo.servlet.port> -->
        <cargo.jvmargs>-Xmx2048m -Xms512m</cargo.jvmargs>
        <cargo.start.jvmargs>-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000</cargo.start.jvmargs>
      </properties>
    </configuration>
  </configuration>
</plugin>

然后,您需要在 IDE 中的端口 8000 上创建远程调试配置(如果未指定任何内容,则默认为端口)

更多命令在这里 : https://codehaus-cargo.github.io/cargo/Maven2+plugin.html#Maven2plugin-TheCargoMavenpluginindetail


推荐