我找不到让Maven的做的Tomcat 7的部署,使使用Tomcat 7的并行部署的标准化方式:找行家做并行部署到Tomcat
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Parallel_deployment
有没有一种可靠的方法去做这个?也许总是保持两个版本的应用程序生活?
我找不到让Maven的做的Tomcat 7的部署,使使用Tomcat 7的并行部署的标准化方式:找行家做并行部署到Tomcat
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Parallel_deployment
有没有一种可靠的方法去做这个?也许总是保持两个版本的应用程序生活?
可以使用tomcat7-maven-plugin这个用例:
<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>
正如你所看到的版本是在path
元素中指定的基础上,在这个例子中,构建时间戳。
当然,如果您不想保留所有旧版本的运行,您仍然需要在您的server.xml <Host>
元素中使用undeployOldVersions="true"
。
同样在这里,所以我写了一个脚本来完成与Maven完全相同的操作,请参阅http://tynamo.org/Zero+downtime+deployment+to+Tomcat+7+with+Maven。此外,Tomcat 7.0.31将具有undeployOldVersions(请参阅https://issues.apache.org/bugzilla/show_bug.cgi?id=52777)。
直接通过Maven做这件事可能是一个挑战。您可以尝试让Maven在打包时将其版本号应用于WAR文件,然后进行部署。
就旧版本而言,“undeployOldVersions”属性将允许Tomcat在不再使用时删除旧版本。
你可以尝试使用更好的Tomcat管理像MeerCat:http://www.meercatmanager.com
它不使用Maven,但它可以部署在多个Tomcat服务器实例相同的应用程序,并轻松地管理他们的部署。一探究竟 !
这就是我在我的问题How do I get Maven to create an appropriately named .war for use with Tomcat 7's parallel deployment feature?得到的。
你的问题真的是它的要点。以下是我所做的。
首先,让Maven生成正确命名的.war文件。我使用了Maven的时间戳插件。
...
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${war.version}</version>
<configuration>
<warName>${war.name}</warName>
</configuration>
</plugin>
...
使用时间戳作为版本保证.war文件根据Tomcat 7用来决定最新版本的规则正确命名。
我找不到任何有关使Tomcat 7 Maven插件与此工作有关的信息。在Maven IRC上提问Tomcat IRC &。也许这是可能的,但我无法实现它的工作。
我所做的是这样的:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>install</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${group.id}</groupId>
<artifactId>${artifact.id}</artifactId>
<version>${version}</version>
<type>war</type>
<overWrite>true</overWrite>
<outputDirectory>${autodeploy.directory}</outputDirectory>
<destFileName>${war.name}.war</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
...
这只是副本从一个地方到另外一个文件。在这种情况下,您为Tomcat的自动部署目录构建的.war。
如果您使用Jenkins进行部署,则可以将该副本设置为生成后操作。 (使用觇/应用程序的名字*的.war为EAR/WAR文件名。)
只是为了完整性,这里是指各种属性:
<properties>
<artifact.id>myApp</artifact.id>
<version>1.0</version>
<group.id>com.example.${artifact.id}</group.id>
<autodeploy.directory xml:space="preserve">C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps</autodeploy.directory>
<war.name>${artifact.id}##${maven.build.timestamp}</war.name>
...
(注意xml:space="preserve"
使Windows快乐当有空间)
Tomcat 7将默认自动部署,但不会删除旧版本。也许这就是你想要的,因为如果你搞砸了某些东西,并且需要取消部署最新版本,那么你将拥有所有旧版本。
但是,如果你想写在钢笔,可以这么说,找到conf /服务器。xml从Tomcat 7安装目录。让<Host>
是这个样子:
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" undeployOldVersions="true">
undeployOldVersions="true"
是神奇的。
就是这样。现在,当您执行maven clean install
时,它会构建一个很好命名的战争,并将其放入Tomcat的自动部署目录中,并且它应该可以正常工作。
-Colin
感谢您分享这颗宝石!另一个补充,为了调整时间戳格式,可以按照这里提供的指令进行操作:http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Available_Variables – bertie
解决方案是使用Cargo插件。
请在以下3个配置文件,使您可以:
请注意'上下文'属性,允许在使用##进行部署期间重命名工件以进行并行部署。
<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>
我没有使用MTOMCAT的经验,但可以定义您将要部署的WAR文件的名称吗?如果是这样,只要确保它被称为'mywebapp ## version.war'。 –