我需要从Maven运行服务器(在Java类中实现),但是如果使用exec:java目标,它将阻塞maven,并且不会传递到连接到服务器的下一个阶段。
有什么办法可以在不中断Maven执行的情况下异步运行exec:java任务?
谢谢!
最佳答案
您可以使用exec-maven-plugin运行 shell 程序脚本,该脚本将启动您的进程并从中分离(让进程在后台运行)。像这样的东西:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>start-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>src/test/scripts/run.sh</executable>
<arguments>
<argument>{server.home}/bin/server</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
在哪里run.sh可能是这样的(对于U * nix平台):
#! /bin/sh
$* > /dev/null 2>&1 &
exit 0
这应该够了吧。
关于maven - 从Maven运行Java服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10898404/