【问题标题】:Maven and Exec: forking a process?Maven 和 Exec:分叉一个进程?
【发布时间】:2011-06-07 19:38:07
【问题描述】:

我正在尝试使用 Maven 来启动应用程序,然后再对其进行一些集成测试。我在 Windows 上。我的 Maven 插件配置如下所示:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.1</version>
    <executions>
        <execution>
            <id>start-my-application</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>start_application.bat</executable>
                <workingDirectory>./path/to/application</workingDirectory>
            </configuration>
        </execution>
    <executions>
<plugin>

我的批处理文件如下所示:

start myApplication.exe

单独运行时,批处理文件会生成一个单独的窗口来运行应用程序并立即返回控制权。

然而,当从 Maven 运行时,构建会等待单独窗口中的进程完成,然后再继续。这在某种程度上违背了集成测试阶段的意义......

我有什么想法可以在 Maven 中启动一个真正独立的进程以允许构建继续进行吗?

【问题讨论】:

    标签: maven exec


    【解决方案1】:

    为了记录,一个相当老套的解决方案是使用maven-antrun-plugin 调用Ant,它能够产生单独的进程:

    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.6</version>
        <executions>
            <execution>
                <phase>pre-integration-test</phase>
                <configuration>
                    <target>
                        <exec executable="cmd"
                              dir="./path/to/application"
                              spawn="true">
                            <arg value="/c"/>
                            <arg value="start_application.bat"/>
                        </exec>
                    </target>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
           </execution>
       </executions>
    </plugin>
    

    【讨论】:

      【解决方案2】:

      试试这个:

      <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <version>1.1</version>
          <executions>
              <execution>
                  <id>start-my-application</id>
                  <phase>pre-integration-test</phase>
                  <goals>
                      <goal>exec</goal>
                  </goals>
                  <configuration>
                      <executable>call</executable>
                      <arguments>
                          <argument>start_application.bat</argument>
                      </arguments>
                      <workingDirectory>./path/to/application</workingDirectory>
                  </configuration>
              </execution>
          </executions>
      </plugin>
      

      【讨论】:

      • 恐怕不走运 - 会出现一个单独的 cmd shell 窗口,但创建它的原始 mvn 调用会阻塞并等待它...
      • 嗯,奇怪。在我的测试中,这似乎有效。哦,好吧 - 抱歉,它对你不起作用。
      • 另外,这仅适用于 Windows。 (对 OP 很好,但对其他人可能不是。)
      猜你喜欢
      • 2019-05-13
      • 1970-01-01
      • 2021-05-31
      • 2012-04-19
      • 1970-01-01
      • 2013-06-06
      • 1970-01-01
      • 2012-11-30
      • 2012-04-13
      相关资源
      最近更新 更多