Java Tomcat 8 与 Maven 的集成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24271213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tomcat 8 integration with Maven
提问by Débora
It sounds like Eclipse (Kepler) does not have a proper plugin for Tomcat 8. I want to deploy my .war into Tomcat 8 and run it by Maven pom.xml file. Can anyone provide me step-by-step guidance or any resources, please?
听起来 Eclipse (Kepler) 没有适合 Tomcat 8 的插件。我想将我的 .war 部署到 Tomcat 8 并通过 Maven pom.xml 文件运行它。任何人都可以为我提供分步指导或任何资源吗?
My POM file:
我的 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>
回答by NimChimpsky
Can you use the cargo pluygin instead, this works for me, deploying to tomcat8 :
你能改用cargo 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>
回答by C Wang
For Tomcat 8, you should use cargo-maven2-plugin, which works for both maven 2 and maven 3. When configuration cargo plugin, make sure that the value for Container Id is "tomcat8x". Do NOT omit the "x" after tomcat8.
对于Tomcat 8,你应该使用cargo-maven2-plugin,它适用于maven 2和maven 3。配置cargo插件时,确保Container Id的值为“tomcat8x”。不要在 tomcat8 之后省略“x”。
回答by Ronan Quillevere
Example of how to run your war with cargo & tomcat8
如何使用货物和 tomcat8 运行War的示例
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
If you want to add it to your pom
如果你想把它添加到你的 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>
Then to run you war (if your pom is a war)
然后运行你的War(如果你的 pom 是一场War)
mvn cargo:run
To run with debug (memory options not necessary)
使用调试运行(不需要内存选项)
<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>
Then you need to create a remote debug configuration in your IDE on port 8000 (port by default if nothing specified)
然后您需要在 IDE 中的 8000 端口上创建远程调试配置(如果未指定任何端口,则为默认端口)
More commands here : https://codehaus-cargo.github.io/cargo/Maven2+plugin.html#Maven2plugin-TheCargoMavenpluginindetail
更多命令在这里:https: //codehaus-cargo.github.io/cargo/Maven2+plugin.html#Maven2plugin-TheCargoMavenpluginindetail
回答by Borgy Manotoy
Just in case you use a separate Tomcat local server. If you use embedded tomcat, this is not applicable.
以防万一您使用单独的 Tomcat 本地服务器。如果使用嵌入式 tomcat,则不适用。
In your pom.xml, add the tomcat plugin. (You can use this for both Tomcat 7 and 8):
在您的 pom.xml 中,添加 tomcat 插件。(您可以将它用于 Tomcat 7 和 8):
pom.xml
pom.xml
<!-- Tomcat plugin -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http:// localhost:8080/manager/text</url>
<server>TomcatServer</server> *(From maven > settings.xml)*
<username>*yourtomcatusername*</username>
<password>*yourtomcatpassword*</password>
</configuration>
</plugin>
tomcat-users.xml
tomcat-users.xml
<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="password" roles="manager-gui,manager-script" />
</tomcat-users>
settings.xml (maven > conf)
settings.xml (maven > conf)
<servers>
<server>
<id>TomcatServer</id>
<username>admin</username>
<password>password</password>
</server>
</servers>
* deploy/re-deploy
* 部署/重新部署
mvn tomcat7:deployOR mvn tomcat7:redeploy
mvn tomcat7:deploy或 mvn tomcat7:redeploy
Tried this on (Both Ubuntu and Windows 8/10):
* Jdk 7 & Tomcat 7
* Jdk 7 & Tomcat 8
* Jdk 8 & Tomcat 7
* Jdk 8 & Tomcat 8
在(Ubuntu 和 Windows 8/10)上尝试过:
* Jdk 7 & Tomcat 7
* Jdk 7 & Tomcat 8
* Jdk 8 & Tomcat 7
* Jdk 8 & Tomcat 8
Tested on Both Jdk 7/8 & Tomcat 7/8. (Works with Tomcat 8.5 Also, will test Tomcat 9 soon)
在 Jdk 7/8 和 Tomcat 7/8 上测试。(适用于 Tomcat 8.5 此外,将很快测试 Tomcat 9)
Note:
Tomcat manager should be running or properly setup, before you can use it with maven.
注意:
Tomcat 管理器应该正在运行或正确设置,然后才能与 maven 一起使用。