1

I have a reactor project with the following structure

server
- pom.xml (parent) 
-- appserver (has a server socket)
-- webserver (connects to the socket in appserver and gets data)

The appserver pom.xml has a maven-exec-plugin that runs the main method in my java class AppServer.

When I run goal verify in my topmost (server) project my build gets stuck at appserver - exec goal and never proceeds to building / running my webserver.

Ideally I would like to run my appserver first and then my webserver in a single install or verify run on my top most project.

Here is the exec maven plugin configuration in my appserver pom.

<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId> 
<executions> 
  <execution> 
    <goals> 
      <goal>java</goal> 
    </goals> 
  </execution> 
</executions> 
<configuration> 
  <mainClass>somepackage.AppServer</mainClass> 
</configuration> 

I am aware that many other questions of similar nature have been asked before and most answers revolve around use of shell scripts with antrun plugin and almost all of them atleast 3 / 4 years old and I hope there is new solution in a more platform independent manner available now.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Gautam
  • 1,030
  • 13
  • 37
  • I'm afraid I don't understand your problem. What do you want to do here? Could you tell us what your project is about, what it's supposed to do, and what it's not doing? – Tunaki Feb 16 '16 at 16:07
  • When I run mvn verify on topmost project my build process gets stuck at running my java class in my AppServer as it is a blocking process. I would like the build to continue and run my webserver afterwards. – Gautam Feb 16 '16 at 16:09
  • 1
    Ha, you'll have more luck with the [`exec`](http://www.mojohaus.org/exec-maven-plugin/examples/example-exec-for-java-programs.html) goal (instead of `java`). It executes in a forked VM. You can make it call a shell script that starts a background process. See here: http://stackoverflow.com/q/27804862/1743880 – Tunaki Feb 16 '16 at 16:13
  • @Tunaki I am on windows and my CI is on linux.. I am afraid this is not a solution for me – Gautam Feb 16 '16 at 16:15

1 Answers1

1

There are unfortunately no better solutions than using the maven-antrun-plugin for your use-case. maven-exec-plugin can be used to launch an external process, either in the same VM with the java goal or in a forked VM with the exec goal, but in both cases, it will be blocking; meaning that the plugin will wait for the execution to finish. The possible work-around of starting a Shell script as mentioned here and here works well in Linux environment. It won't work in your case however because you need to support multiple environments.

With the maven-antrun-plugin, you can use the Exec task and set the spawn attribute to true. This will cause Ant to run the task in the background. A sample configuration would be:

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.8</version>
  <executions>
    <execution>
      <phase> <!-- a lifecycle phase --> </phase>
      <configuration>
        <target>
          <property name="runtime_classpath" refid="maven.runtime.classpath" />
          <exec executable="java" spawn="true">
            <arg value="-classpath"/>
            <arg value="${runtime_classpath}"/>
            <arg value="somepackage.AppServer"/>
          </exec>  
        </target>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Note that this uses the maven.runtime.classpath to refer to the Maven classpath containing all runtime dependencies (see here for more info).

Community
  • 1
  • 1
Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • Precise.. very Precise :) hooked it to verify phase and it worked like a charm and I believe its platform independent as well which is the bonus I need. – Gautam Feb 17 '16 at 07:58