让maven对Tomcat进行并行部署
我找不到一种标准化的方法让Maven使用Tomcat 7的并行部署来进行Tomcat 7部署:让maven对Tomcat进行并行部署,tomcat,maven,Tomcat,Maven,我找不到一种标准化的方法让Maven使用Tomcat 7的并行部署来进行Tomcat 7部署: 有没有可靠的方法可以做到这一点?也许总是保持两个版本的应用程序处于活动状态?在这里是一样的,所以我写了一个脚本来与Maven完全一样,请参见。另外,Tomcat7.0.31将有未部署的版本(请参阅)。直接通过Maven实现这一点可能是一个挑战。您可以尝试让Maven在打包时将其版本号应用于WAR文件,然后部署它 对于旧版本,“undeployOldVersions”属性将允许Tomcat在旧版本不再
有没有可靠的方法可以做到这一点?也许总是保持两个版本的应用程序处于活动状态?在这里是一样的,所以我写了一个脚本来与Maven完全一样,请参见。另外,Tomcat7.0.31将有未部署的版本(请参阅)。直接通过Maven实现这一点可能是一个挑战。您可以尝试让Maven在打包时将其版本号应用于WAR文件,然后部署它
对于旧版本,“undeployOldVersions”属性将允许Tomcat在旧版本不再使用时删除它。您可以尝试使用更好的Tomcat管理器,如MeerCat:
它不使用Maven,但可以在多个Tomcat服务器实例上部署相同的应用程序,并轻松管理它们的部署。看看 这就是我在问题中的意思 你的问题才是重点。下面是我所做的 首先,让Maven生成正确命名的.war文件。我使用了Maven的时间戳插件
...
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${war.version}</version>
<configuration>
<warName>${war.name}</warName>
</configuration>
</plugin>
...
undeployOldVersions=“true”
就是魔法
真的是这样。现在,当您执行maven clean安装时
,它将构建一个名称很好的war,并将其放入Tomcat的autodeploy目录中,它应该可以正常工作
-Colin解决方案是使用Cargo插件 请查找以下3个允许您:
- 本地部署到Cargo自动安装的Tomcat
- 本地部署到已安装并启动的Tomcat
- 远程部署
<profiles>
<profile>
<!-- Local deploy - tomcat 7 automatically installed by Cargo -->
<id>local_deploy_auto_install</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<zipUrlInstaller>
<url>http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.35/bin/apache-tomcat-7.0.35.zip</url>
</zipUrlInstaller>
</container>
<deployables>
<deployable>
<properties>
<context>${project.artifactId}##${project.version}</context>
</properties>
</deployable>
</deployables>
<configuration>
<properties>
<cargo.servlet.port>9080</cargo.servlet.port>
</properties>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- Local deploy - tomcat 7 must have been installed and started -->
<id>local_deploy</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<!-- When Cargo starts the container, the following tag instructs it to wait for you to kill the session with Crtl-C -->
<!-- <wait>true</wait> -->
<!-- The following tag details the container you want to deploy to. -->
<container>
<!-- Specifying "tomcat7x" is very important! This one tripped me up for quite a while. The issue is that instead
of being an identifier for you, "tomcat7x" is an identifier for Cargo that you want to deploy your webapp in Tomcat 7.x.
I had initially thought otherwise and hence just dropped the 'x', making it "tomcat7", but that never worked. -->
<containerId>tomcat7x</containerId>
<!-- Type == Installed means that you want to deploy to a container that's installed on your computer -->
<type>installed</type>
</container>
<configuration>
<!-- This is another one that confused me for long. Its not enough to specify 'installed' in the container tag. You
have to now specify another configuration with type == existing and the home path -->
<type>existing</type>
<home>${basedir}/../../tomcat7.0.37</home>
</configuration>
<!-- Here you specify 'deployables' -->
<deployables>
<!-- This deployable specifies the webapp you want to deploy -->
<deployable>
<properties>
<context>${project.artifactId}##${project.version}</context>
</properties>
</deployable>
</deployables>
</configuration>
<!-- Executions specify the targets that you want to run during build -->
<executions>
<!-- Maven has the concept of a 'phase' which can be thought of a collection of goals. Hence here we are specifying
that during the 'install' phase first deploy the webapp to the container specific folder and then start the container. Both
'deployer-deploy' and 'start' are cargo specific goals. -->
<execution>
<id>verify-deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- Remote dans un tomcat7 pré-installé, pré-démarré -->
<id>remote_deploy</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<!-- When Cargo starts the container, the following tag instructs it to wait for you to kill the session with Crtl-C -->
<!-- <wait>true</wait> -->
<!-- The following tag details the container you want to deploy to. -->
<container>
<!-- Specifying "tomcat7x" is very important! This one tripped me up for quite a while. The issue is that instead
of being an identifier for you, "tomcat7x" is an identifier for Cargo that you want to deploy your webapp in Tomcat 7.x.
I had initially thought otherwise and hence just dropped the 'x', making it "tomcat7", but that never worked. -->
<containerId>tomcat7x</containerId>
<!-- Type == Installed means that you want to deploy to a container that's installed on your computer -->
<type>remote</type>
</container>
<configuration>
<!-- This is another one that confused me for long. Its not enough to specify 'installed' in the container tag. You
have to now specify another configuration with type == existing and re-issue the home path -->
<type>runtime</type>
<properties>
<cargo.protocol>http</cargo.protocol>
<cargo.hostname>192.168.0.6</cargo.hostname>
<cargo.servlet.port>8080</cargo.servlet.port>
<cargo.remote.username>deploy</cargo.remote.username>
<cargo.remote.password>purplerain</cargo.remote.password>
</properties>
</configuration>
<!-- Here you specify 'deployables' -->
<deployables>
<!-- This deployable specifies the webapp you want to deploy -->
<deployable>
<properties>
<context>${project.artifactId}##${project.version}</context>
</properties>
</deployable>
</deployables>
</configuration>
<!-- Executions specify the targets that you want to run during build -->
<executions>
<!-- Maven has the concept of a 'phase' which can be thought of a collection of goals. Hence here we are specifying
that during the 'install' phase first deploy the webapp to the container specific folder and then start the container. Both
'deployer-deploy' and 'start' are cargo specific goals. -->
<execution>
<id>verify-deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
本地部署自动安装
org.codehaus.cargo
cargo-maven2-plugin
tomcat7x
http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.35/bin/apache-tomcat-7.0.35.zip
${project.artifactId}{project.version}
9080
本地部署
org.codehaus.cargo
cargo-maven2-plugin
tomcat7x
安装
现有的
${basedir}/../../tomcat7.0.37
${project.artifactId}{project.version}
验证部署
安装
部署
远程部署
org.codehaus.cargo
cargo-maven2-plugin
tomcat7x
遥远的
运行时
http
192.168.0.6
8080
部署
紫癜素
${project.artifactId}{project.version}
验证部署
安装
部署
对于此用例,您可以使用:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/WebappName##${maven.build.timestamp}</path>
<url>http://localhost:8080/manager/text</url>
<username>tomcat</username>
<password>tomcat</password>
<update>true</update>
</configuration>
</plugin>
org.apache.tomcat.maven
tomcat7 maven插件
2.2
/WebappName##${maven.build.timestamp}
http://localhost:8080/manager/text
雄猫
雄猫
真的
正如您所看到的,版本是在path
元素中根据中的构建时间戳指定的
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" undeployOldVersions="true">
<profiles>
<profile>
<!-- Local deploy - tomcat 7 automatically installed by Cargo -->
<id>local_deploy_auto_install</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<zipUrlInstaller>
<url>http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.35/bin/apache-tomcat-7.0.35.zip</url>
</zipUrlInstaller>
</container>
<deployables>
<deployable>
<properties>
<context>${project.artifactId}##${project.version}</context>
</properties>
</deployable>
</deployables>
<configuration>
<properties>
<cargo.servlet.port>9080</cargo.servlet.port>
</properties>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- Local deploy - tomcat 7 must have been installed and started -->
<id>local_deploy</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<!-- When Cargo starts the container, the following tag instructs it to wait for you to kill the session with Crtl-C -->
<!-- <wait>true</wait> -->
<!-- The following tag details the container you want to deploy to. -->
<container>
<!-- Specifying "tomcat7x" is very important! This one tripped me up for quite a while. The issue is that instead
of being an identifier for you, "tomcat7x" is an identifier for Cargo that you want to deploy your webapp in Tomcat 7.x.
I had initially thought otherwise and hence just dropped the 'x', making it "tomcat7", but that never worked. -->
<containerId>tomcat7x</containerId>
<!-- Type == Installed means that you want to deploy to a container that's installed on your computer -->
<type>installed</type>
</container>
<configuration>
<!-- This is another one that confused me for long. Its not enough to specify 'installed' in the container tag. You
have to now specify another configuration with type == existing and the home path -->
<type>existing</type>
<home>${basedir}/../../tomcat7.0.37</home>
</configuration>
<!-- Here you specify 'deployables' -->
<deployables>
<!-- This deployable specifies the webapp you want to deploy -->
<deployable>
<properties>
<context>${project.artifactId}##${project.version}</context>
</properties>
</deployable>
</deployables>
</configuration>
<!-- Executions specify the targets that you want to run during build -->
<executions>
<!-- Maven has the concept of a 'phase' which can be thought of a collection of goals. Hence here we are specifying
that during the 'install' phase first deploy the webapp to the container specific folder and then start the container. Both
'deployer-deploy' and 'start' are cargo specific goals. -->
<execution>
<id>verify-deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- Remote dans un tomcat7 pré-installé, pré-démarré -->
<id>remote_deploy</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<!-- When Cargo starts the container, the following tag instructs it to wait for you to kill the session with Crtl-C -->
<!-- <wait>true</wait> -->
<!-- The following tag details the container you want to deploy to. -->
<container>
<!-- Specifying "tomcat7x" is very important! This one tripped me up for quite a while. The issue is that instead
of being an identifier for you, "tomcat7x" is an identifier for Cargo that you want to deploy your webapp in Tomcat 7.x.
I had initially thought otherwise and hence just dropped the 'x', making it "tomcat7", but that never worked. -->
<containerId>tomcat7x</containerId>
<!-- Type == Installed means that you want to deploy to a container that's installed on your computer -->
<type>remote</type>
</container>
<configuration>
<!-- This is another one that confused me for long. Its not enough to specify 'installed' in the container tag. You
have to now specify another configuration with type == existing and re-issue the home path -->
<type>runtime</type>
<properties>
<cargo.protocol>http</cargo.protocol>
<cargo.hostname>192.168.0.6</cargo.hostname>
<cargo.servlet.port>8080</cargo.servlet.port>
<cargo.remote.username>deploy</cargo.remote.username>
<cargo.remote.password>purplerain</cargo.remote.password>
</properties>
</configuration>
<!-- Here you specify 'deployables' -->
<deployables>
<!-- This deployable specifies the webapp you want to deploy -->
<deployable>
<properties>
<context>${project.artifactId}##${project.version}</context>
</properties>
</deployable>
</deployables>
</configuration>
<!-- Executions specify the targets that you want to run during build -->
<executions>
<!-- Maven has the concept of a 'phase' which can be thought of a collection of goals. Hence here we are specifying
that during the 'install' phase first deploy the webapp to the container specific folder and then start the container. Both
'deployer-deploy' and 'start' are cargo specific goals. -->
<execution>
<id>verify-deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/WebappName##${maven.build.timestamp}</path>
<url>http://localhost:8080/manager/text</url>
<username>tomcat</username>
<password>tomcat</password>
<update>true</update>
</configuration>
</plugin>