How to deploy war with automatic buildnumber to to

2019-07-20 02:57发布

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>

I uses below command when I build and deploy to Tomcat.

mvn clean tomcat:redeploy 

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.

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

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-07-20 03:31

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>

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.

查看更多
登录 后发表回答