Special treatment of some command line arguments and configuration parameters facilitate the running of Java programs in external processes.
Note: with the java mojo, there are some confusion caused by the almost duplication of functionality between the arguments and commandArgs configuration parameters.
See http://jira.codehaus.org/browse/MEXEC-59 for discussion.
If specified as part of the exec.args argument, the special string %classpath will be replaced by the project classpath as computed by Maven.
mvn exec:exec -Dexec.executable="java" [...] -Dexec.args="%classpath"
To execute Java programs, the Exec Plugin helps by allowing the <classpath> special argument:
<configuration>
<executable>java</executable>
<arguments>
<argument>-Dmyproperty=myvalue</argument>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies,
also adding the project build directory -->
<classpath/>
<argument>com.example.Main</argument>
...
</arguments>
</configuration>or if one wants to restrict the dependencies in the classpath:
<configuration>
<executable>java</executable>
<arguments>
<argument>-Dmyproperty=myvalue</argument>
<argument>-classpath</argument>
<classpath>
<dependency>commons-io:commons-io</dependency>
<dependency>commons-lang:commons-lang</dependency>
</classpath>
<argument>com.example.Main</argument>
...
</arguments>
</configuration>