【问题标题】:run maven exec-maven-plugin as last step最后一步运行 maven exec-maven-plugin
【发布时间】:2011-07-03 20:48:06
【问题描述】:

我想在“mvn test”之后使用 exec-maven-plugin 执行命令行脚本如何在 pom.xml 下设置?

【问题讨论】:

    标签: maven-2 maven


    【解决方案1】:

    您可以只从项目网站上获取示例,并且必须在执行中添加一个阶段。我刚刚用下面的这个 pom 进行了测试,它工作正常。

        <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.stackoverflow</groupId>
      <artifactId>q5110133</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2</version>
            <executions>
              <execution>
                <id>Test.bat</id>
                <phase>test</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <executable>c:\temp\test.bat</executable>
              <!-- optional -->
              <workingDirectory>C:\temp</workingDirectory>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>
    

    【讨论】:

    • 你应该使用 &lt;phase&gt;test&lt;/phase&gt; (至少那是 OP 之后的内容)
    • @Sean Patrick:install 可能不是示例的最佳选择。这只是我知道会发生的一个阶段:-)我已经改变了。
    • 这可行,但我有一个“下一步”问题:如果上面示例的“test.bat”能够生成“JUnit XML 报告”文件怎么办?我如何把它还给 Maven?有什么想法/例子吗?
    • @Detro:这取决于你想用它做什么——一般来说,你可以在构建过程中使用目标文件夹中的文件。也许最好将其作为一个问题提出,以便其他人也能找到它。
    • 对我来说,正确的步骤是在创建 jar 后想要运行某些东西时安装。完美运行。感谢您为像我这样的新手分享完整的pom.xml
    【解决方案2】:

    排序的要点是,您必须选择一个执行阶段,该阶段位于测试阶段之后。您可以在 Maven 构建生命周期中看到这一点。

    例如,您可以使用prepare-package,它是直接在测试阶段之后的阶段。

    顺便说一句:插件在同一生命周期中配置时,按照它们在 pom.xml 中列出的顺序执行。

    【讨论】:

      猜你喜欢
      • 2014-04-19
      • 2014-04-23
      • 2016-01-31
      • 1970-01-01
      • 2012-03-13
      • 2012-03-03
      • 2011-01-12
      • 2017-08-02
      • 2015-07-06
      相关资源
      最近更新 更多