You can formally specify all the relevant execution information in the plugin configuration. Depending on your cases, you can also specify some or all information using system properties.
Using the system properties you would just execute it like the following example.
> mvn exec:exec -Dexec.executable="maven" [-Dexec.workingdir="/tmp"] -Dexec.args="-X myproject:dist"
Add configuration similar to the following to your POM:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1-beta-2</version>
<executions>
<execution>
...
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>maven</executable>
<!-- optional -->
<workingDirectory>/tmp</workingDirectory>
<arguments>
<argument>-X</argument>
<argument>myproject:dist</argument>
...
</arguments>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
This mojo helps you run a Java program within the same VM as maven.
The mojo goes to great length to try to mimic the way the VM works, but there are some small subttle differences. Today all differences come from the way the mojo deals with thread management .
| command line | Java Mojo |
| the VM exits as soon as the only remaining threads are daemon threads |
By default daemon threads are joined and interrupted once all known non daemon threads have quitted. The join timeout is customisable The user might wish to further cleanup cleanup by stopping the unresponsive threads. The user can disable the full extra thread management (interrupt/join/[stop]) |
Read the java for more information on how to configure this behavior.
If you find out that these differences are unacceptable for your case, you may need to use the exec mojo to wrap your java executable.
If you want to execute Java programs in the same VM, you can either use the command line version
> mvn exec:java -Dexec.mainClass="com.example.Main" [-Dexec.args="argument1"] ...
either configure the plugin in your pom:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1-beta-2</version>
<executions>
<execution>
...
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.Main</mainClass>
<arguments>
<argument>argument1</argument>
...
</arguments>
<systemProperties>
<systemProperty>
<key>myproperty</key>
<value>myvalue</value>
</systemProperty>
...
</configuration>
</plugin>
</plugins>
</build>
...
</project>
Note: the java goal doesn't spawn a new process. Any VM specific option that you want to pass to the executed class must be passed to the maven VM using the MAVEN_OPTS environment variable. E.g.
MAVEN_OPTS=-Xmx1024m
Otherwise consider using the exec goal.