Today we will look into the Tomcat Maven Plugin (tomcat7-maven-plugin) that helps us in deploying our WAR files to Tomcat easily.
今天,我们将研究Tomcat Maven插件(tomcat7-maven-plugin),该插件可帮助我们轻松地将WAR文件部署到Tomcat。
Tomcat Maven部署 (Tomcat Maven Deploy)
Recently I was developing a web application and after doing the build, I used to copy the generated WAR file to Tomcat webapps directory. It was time-consuming, boring and sometimes I used to miss the updated WAR file to copy and notice it later on.
最近,我正在开发一个Web应用程序,并在完成构建后,将复制的WAR文件复制到Tomcat webapps目录中。 这很耗时,很无聊,有时我曾经错过了更新的WAR文件来复制并在以后注意到它。
Then I decided to look for some configurations through which I can configure Maven build to deploy the generated WAR file into tomcat automatically.
然后,我决定寻找一些配置,通过这些配置可以配置Maven构建,以将生成的WAR文件自动部署到tomcat中。
My first approach was to use Maven plugins to copy the generated WAR file to tomcat deploy directory.
我的第一种方法是使用Maven插件将生成的WAR文件复制到tomcat部署目录。
For example, below was the pom.xml file for my simple web application, I have removed all the unwanted stuff to keep it clear.
例如,以下是我的简单Web应用程序的pom.xml文件,我删除了所有不需要的内容以使其清晰可见。
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MyWebapp</groupId>
<artifactId>MyWebapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I used maven-antrun-plugin
to add another task for the integration-test
phase where I am copying the WAR file to my local tomcat directory.
我使用maven-antrun-plugin
为integration-test
阶段添加了另一个任务,在该阶段,我将WAR文件复制到本地tomcat目录中。
<