3

我使用 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 插件找不到战争文件,因为 buildernumber 插件将战争文件名设置为递增版本号。我想部署战争文件仍然使用 buildnumber 插件。我该如何解决这个问题?您的回答将不胜感激。

相关: buildnumber-maven-plugin 属性 ${buildNumber} 的可见性

4

1 回答 1

1

使用 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 中使用的部分不止一个 pom,例如“maven-compiler-plugin”,放在父 pom 中并包含在所有项目 pom 中。

于 2014-04-27T06:22:53.300 回答