该插件提供了多种将应用部署到 Tomcat 的方法。
以下将详细描述这些方法。
将 WAR 项目部署到 Tomcat 的最简单方法是键入
mvn tomcat:deploy
此目标将使用 HTTP PUT 方式将 WAR 文件组装并部署到 Tomcat 的管理器。
要指定不同的 WAR 文件位置,请在您的pom.xml中添加以下插件配置块:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.2</version> <configuration> <warFile>path/to/my/warFile.war</warFile> </configuration> </plugin> ... </plugins> ... </build> ... </project>
默认位置是${project.build.directory}/${project.build.finalName}.war.
为避免在部署时构建 WAR 文件,可以通过键入以下命令将 WAR 目录部署到 Tomcat:
mvn war:exploded tomcat:exploded
要指定不同的 WAR 目录位置,请在您的 pom.xml 中添加一个插件配置块:pom.xml中添加以下插件配置块:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.2</version> <configuration> <warDirectory>path/to/my/warDir</warDirectory> </configuration> </plugin> ... </plugins> ... </build> ... </project>
默认位置是${project.build.directory}/${project.build.finalName}.
要在部署 WAR 目录时提供 context.xml,请在您的context.xmlpom.xml 中添加一个插件配置块:pom.xml中添加以下插件配置块:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.2</version> <configuration> <mode>both</mode> </configuration> </plugin> ... </plugins> ... </build> ... </project>
默认的 context.xmlcontext.xml文件使用位置在src/main/webapp/META-INF/context.xml.
要指定不同的 context.xmlcontext.xml文件位置,请在您的 pom.xml 中添加一个插件配置块:pom.xml中添加以下插件配置块:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.2</version> <configuration> <contextFile>path/to/my/contextFile.xml</contextFile> </configuration> </plugin> ... </plugins> ... </build> ... </project>
默认位置是${project.build.directory}/${project.build.finalName}/META-INF/context.xml.
为避免将资源复制到构建目录,可以通过键入以下命令将 Web 应用程序源目录部署到 Tomcat:
mvn war:inplace tomcat:inplace
要指定不同的 WAR 目录位置,请在您的 pom.xml 中添加一个插件配置块:pom.xml中添加以下插件配置块:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.2</version> <configuration> <warSourceDirectory>path/to/my/warSourceDir</warSourceDirectory> </configuration> </plugin> ... </plugins> ... </build> ... </project>
默认位置是${basedir}/src/main/webapp.
要在部署 WAR 目录时提供 context.xml,请在您的context.xml在将 WAR 目录部署到 Tomcat 时,请在您的 pom.xml 中添加一个插件配置块:pom.xml中添加以下插件配置块:
<project> ... <build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.2</version> <configuration> <mode>both</mode> </configuration> </plugin> </plugins> </build> ... </project>
默认的 context.xmlcontext.xml使用的 context.xml 文件位于src/main/webapp/META-INF/context.xml.
要指定不同的 context.xmlcontext.xml文件位置,请在您的 pom.xml 中添加一个插件配置块:pom.xml中添加以下插件配置块:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.2</version> <configuration> <contextFile>path/to/my/contextFile.xml</contextFile> </configuration> </plugin> ... </plugins> ... </build> ... </project>
默认位置是${project.build.directory}/${project.build.finalName}/META-INF/context.xml.
若要简单地将 context.xmlcontext.xml文件部署到 Tomcat
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.2</version> <configuration> <mode>context</mode> </configuration> </plugin> ... </plugins> ... </build> ... </project>
mvn tomcat:deploy
默认的 context.xmlcontext.xml使用的 context.xml 文件位于src/main/webapp/META-INF/context.xml.
要指定不同的 context.xmlcontext.xml文件位置,请在您的 pom.xml 中添加一个插件配置块:pom.xml中添加以下插件配置块:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.2</version> <configuration> <contextFile>path/to/my/contextFile.xml</contextFile> </configuration> </plugin> ... </plugins> ... </build> ... </project>
默认位置是${project.build.directory}/${project.build.finalName}/META-INF/context.xml.