【问题标题】:How to deploy war with automatic buildnumber to tomcat using maven tomcat plugin如何使用 maven tomcat 插件将带有自动构建号的战争部署到 tomcat
【发布时间】:2013-08-30 00:23:39
【问题描述】:

我使用 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 插件。我该如何解决这个问题? 您的回答将不胜感激。

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

【问题讨论】:

    标签: maven deployment


    【解决方案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 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-19
      • 2012-11-22
      • 2010-11-14
      • 2013-03-23
      • 2014-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多