1

I have this multi module maven project, with one parent pom and many child poms.

when running maven install, my last module uses a maven exec plugin and runs a main method of some class. The thing is, it seems like the build is stopped once the main method finishes running.

This is my setup:

from my parent pom:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>3.0.0</version>
  <configuration>
    <skip>true</skip>
    <executable>java</executable>
  </configuration>
</plugin>

from my child pom:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.1.1</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>java</goal>
                </goals>
                <configuration>
                    <mainClass>com.example.MainClass</mainClass>
                    <async>true</async>
                    <keepAlive>true</keepAlive>
                </configuration>
            </execution>
        </executions>
    </plugin>

I tried incorporating

<async>true</async>
<keepAlive>true</keepAlive>

but it still stops after the main method is executed. I do not see BUILD SUCCESS in the end...

eaRobust
  • 87
  • 6
  • Well, you do have that skip in there. Probably need to remove that. Also there are some fine differences between the java goal and exec goal, make sure you know which flags are enabled by default for each one. You can review those two goals here: https://www.mojohaus.org/exec-maven-plugin/index.html – Michael Peacock Nov 23 '21 at 19:52
  • Why do you use different versions (`3.0.0`, `1.1.1`) of the `exec-maven-plugin`? [`1.1.1` is from 26-Jan-2009!](https://search.maven.org/artifact/org.codehaus.mojo/exec-maven-plugin) – Gerold Broser Nov 23 '21 at 20:05
  • @GeroldBroser for some odd reason, if I don't use 1.1.1, it does not execute the main method. – eaRobust Nov 23 '21 at 20:06
  • Which odd reason? I'm pretty sure that if something goes wrong with `3.0.0` it's _not_ this version's fault. – Gerold Broser Nov 23 '21 at 20:09
  • @GeroldBroser I honestly don't know. – eaRobust Nov 23 '21 at 20:17
  • @GeroldBroser I removed the skip and changed to 3.0.0 and now this version do run my main. But still, it doesn't complete the build. It is important to state that my main ends with System.exit(0) – eaRobust Nov 23 '21 at 20:21
  • [`System.exit()` "_Terminates the currently running Java Virtual Machine._"](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/System.html#exit(int)). See also [return after System.exit() statement in java](https://stackoverflow.com/q/30024860/1744774). – Gerold Broser Nov 23 '21 at 20:33

1 Answers1

1

The solution was to use exec:exec and not exec:java, because exec:java and maven build run on the same process while exec:exec runs on a different process.

eaRobust
  • 87
  • 6