【问题标题】:Why "mvn install" is running my tomcat in Install Phase?为什么“mvn install”在安装阶段运行我的tomcat?
【发布时间】:2015-09-09 13:06:16
【问题描述】:

我已将故障安全与 tomcat7-maven-plugin 一起配置为进行集成测试。当我输入时,它很棒并且效果很好:

mvn clean verify -P integration-test

我的pom.xml是这样的:

        <!-- Runs integration tests -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.18</version>
            <executions>
                <!-- Invokes both the integration-test and the verify goals of the Failsafe Maven plugin -->
                <execution>
                    <id>integration-tests</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                    <configuration>
                        <!-- Skips integration tests if the value of skip.integration.tests property is true -->
                        <skipTests>${skip.integration.tests}</skipTests>
                    </configuration>
                </execution>
            </executions>
        </plugin>


        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
              <path>/onde-vou</path>
            </configuration>
            <executions>
              <execution>
                <id>start-tomcat</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <fork>true</fork>
                </configuration>
              </execution>
              <execution>
                <id>stop-tomcat</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>shutdown</goal>
                </goals>
              </execution>
            </executions>
        </plugin>

但是我遇到了意外的行为。当我输入时:

mvn clean install

它启动tomcat并在进程结束时关闭。 我该如何避免这种行为?这对我没用,我会失去一些秒。

【问题讨论】:

    标签: java maven-3 maven-failsafe-plugin tomcat7-maven-plugin


    【解决方案1】:

    您可以尝试mvn clean install -Dmaven.test.skip=true 跳过测试,从而跳过执行pre-integration-test

    或删除

    <executions>
      <execution>
        <id>start-tomcat</id>
        <phase>pre-integration-test</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <fork>true</fork>
        </configuration>
      </execution>
      <execution>
        <id>stop-tomcat</id>
        <phase>post-integration-test</phase>
        <goals>
          <goal>shutdown</goal>
        </goals>
      </execution>
    </executions>
    

    【讨论】:

    • 很公平,但是第一行呢? mvn clean install -Dmaven.test.skip=true...启动和关闭tomcat是单元测试的一部分...
    • 它没有用。我只需要用于集成测试的tomcat,它正在工作。当我输入 mvn install 时,它首先运行单元测试,最后运行 tomcat 我不知道是什么:Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] --- maven-war-plugin:2.3:war (default-war) @ onde-vou --- [INFO] Building war [INFO] &gt;&gt;&gt; tomcat7-maven-plugin:2.2:run (start-tomcat)
    猜你喜欢
    • 2014-12-16
    • 2016-11-11
    • 2019-06-23
    • 2019-07-27
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 2016-07-17
    • 2016-03-08
    相关资源
    最近更新 更多