Run java server from maven

I need to start the server (implemented in the Java class) from Maven, but if I use the exec: java target, it will block maven and will not proceed to the next steps that connect to the server.

Is there a way to run asynchronous exec: java execution without interrupting maven execution?

Thanks!

+8
maven
source share
3 answers

You can use exec-maven-plugin to run a shell script that will start your process and disconnect from it (letting the process run in the background). Something like that:

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

If run.sh might be like this (for the U * nix platform):

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

That should do the trick.

+5
source share

It looks like you can do this with the antrun plugin:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.3</version> <configuration> <tasks> <java fork="true" spawn="true" classpathref="maven.runtime.classpath" className="fully.qualified.package.App"/> </tasks> </configuration> </plugin> 
0
source share

If you use this server class to perform additional steps of testing integration in your MOM MOV, it is better to consider using a continuous integration tool, for example Jenkins , it has many Plugins , which allows you to start your own classes, start and stop servers, deploy applications and many other features and it's free.

0
source share

All Articles