我需要从Maven运行一个服务器(在Java类中实现)但是如果我使用exec:java目标,它将阻止maven并且它不会传递到连接到服务器的下一个阶段.
有没有办法异步运行exec:java任务,而不会中断maven执行?
谢谢!
您可以使用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 Code Online (Sandbox Code Playgroud)
其中run.sh可能是这样的(对于U*nix平台):
#! /bin/sh
$* > /dev/null 2>&1 &
exit 0
Run Code Online (Sandbox Code Playgroud)
这应该够了吧.