Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run java server from maven

Tags:

maven

I need to run a server(implemented in a Java class) from Maven but if I use the exec:java goal, it will block maven and it will not pass to next phases which connect to the server.

Is there any way to run the exec:java task asynchronously, without interrupting the maven execution?

Thanks!

like image 316
Dan L. Avatar asked Jun 05 '12 13:06

Dan L.


1 Answers

You could use exec-maven-plugin to run shell script which would start your process and detach from it (letting process to run in background). Something like this:

<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> 

Where run.sh could be like this (for U*nix platform):

#! /bin/sh
$* > /dev/null 2>&1 &
exit 0

That should do the trick.

like image 85
maximdim Avatar answered Oct 23 '22 02:10

maximdim