如何使用maven tomcat插件将自动buildnumber的war部署到tomcat

时间:2013-08-30 00:23:39

标签: maven deployment

我使用maven3作为构建工具并有一些插件。这是我的maven设置:

<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时使用以下命令。

mvn clean tomcat:redeploy 

然而,Tomcat插件无法找到war文件,因为buildernumber插件使用增量buildnumber设置war文件名。我想使用buildnumber插件部署war文件。我该如何解决这个问题? 您的回答将不胜感激。

相关:Visibility of buildnumber-maven-plugin property ${buildNumber}

1 个答案:

答案 0 :(得分:0)

使用tomcat 7,使用'##'tomcat7可以使用aritfactId作为上下文,将版本作为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中使用的部分就像'maven-compiler-plugin'一样放在父pom中并包含在你所有的项目poms中。