Maven Exec

24 Dec 2022

Actually that is super easy:

mvn compile exec:java -Dexec.mainClass="com.serg.Main"

mvn compile exec:java -Dexec.mainClass="com.serg.Main" -Dexec.args="one two"

mvn compile exec:java -Dexec.mainClass="com.serg.Main" -Dexec.arguments="arg 1,arg 2"

To get some details about plugin (version and goals)

mvn help:describe -Dplugin=exec

Declare default Main class and arguments:

      <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <mainClass>com.serg.Main</mainClass>
                <arguments>
                    <argument>one</argument>
                    <argument>two</argument>
                    <argument>number three</argument>
                </arguments>
            </configuration>
      </plugin>

After that we can run exec plugin without explicit arguments:

mvn compile exec:java