如何使用Maven tomcat插件将带有自动内部版本号的战争部署到tomcat [英] How to deploy war with automatic buildnumber to tomcat using maven tomcat plugin
问题描述
我正在使用maven3作为构建工具,并且具有一些插件.这是我的Maven设置:
I am using maven3 as build tool and have some plugins. Here is my maven setting:
<build>
<finalName>${project.artifactId}-${project.version}-${buildNumber}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
</manifestEntries>
</archive>
</configuration>
</plugin>
<!-- Build number auto increment -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>buildnumber</id>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<format>{0,number}</format>
<items>
<item>buildNumber</item>
</items>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
</configuration>
</plugin>
<!-- Ignore/Execute plugin execution -->
<!-- copy-dependency plugin -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
<!--
<configuration>
<outputDirectory>${catalina.home}/common/lib</outputDirectory>
</configuration>
-->
</pluginExecutionFilter>
<action>
<ignore/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- webtools plugin to run the project in Tomcat. It also has republish functionality. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
</plugin>
<!-- Codehaus mojo plugin to deploy, run the project in Tomcat -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://127.0.0.1:8080/manager</url>
<server>TomcatServer</server>
</configuration>
</plugin>
</plugin>
在构建并部署到Tomcat时,我使用以下命令.
I uses below command when I build and deploy to Tomcat.
mvn clean tomcat:redeploy
但是Tomcat插件无法找到war文件,因为buildernumber插件使用递增buildnumber设置了war文件名.我想仍然使用buildnumber插件部署war文件.如何解决此问题? 您的回答将不胜感激.
However Tomcat plugin cannot find war file because buildernumber plugin set the war file name with increment buildnumber. I want to deploy war file still using buildnumber plugin. How can I fix this issue? Your answer would be appreciated.
相关: buildnumber-maven-plugin属性$ { buildNumber}
推荐答案
使用带有'##'的tomcat 7,tomcat7可以将aritfactId用作上下文,而将版本用作tomcat中的版本.
Use tomcat 7, with '##' tomcat7 is possible to use the aritfactId as context and the version as version in tomcat.
<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>
<path>/${project.artifactId}##${project.version}</path>
</configuration>
</plugin>
您在pom中使用的部分中,不止一个pom(例如"maven-compiler-plugin")被放置在父pom中,并且包含在所有项目pom中.
Parts in your pom that you use in more that one pom like 'maven-compiler-plugin' put in the parent pom and include in all your project poms.
这篇关于如何使用Maven tomcat插件将带有自动内部版本号的战争部署到tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!