exec:java

Full name:

org.codehaus.mojo:exec-maven-plugin:1.2.1:java

Description:

Executes the supplied java class in the current VM with the enclosing project's dependencies as classpath.

Attributes:

  • Requires a Maven project to be executed.
  • Requires dependency resolution of artifacts in scope: test.
  • Since version: 1.0.
  • Invokes the execution of the lifecycle phase validate prior to executing itself.

Required Parameters

Name Type Since Description
mainClass String 1.0 The main class to execute.

Optional Parameters

Name Type Since Description
arguments String[] 1.0 The class arguments.
classpathScope String 1.0 Defines the scope of the classpath passed to the plugin. Set to compile,test,runtime or system depending on your needs. Since 1.1.2, the default value is 'runtime' instead of 'compile'.
Default value is: runtime.
cleanupDaemonThreads boolean 1.1-beta-1 Wether to interrupt/join and possibly stop the daemon threads upon quitting.
If this is false, maven does nothing about the daemon threads. When maven has no more work to do, the VM will normally terminate any remaining daemon threads.

In certain cases (in particular if maven is embedded), you might need to keep this enabled to make sure threads are properly cleaned up to ensure they don't interfere with subsequent activity. In that case, see daemonThreadJoinTimeout and stopUnresponsiveDaemonThreads for further tuning.


commandlineArgs String 1.0 Arguments for the executed program
daemonThreadJoinTimeout long 1.1-beta-1 This defines the number of milliseconds to wait for daemon threads to quit following their interruption.
This is only taken into account if cleanupDaemonThreads is true. A value <=0 means to not timeout (i.e. wait indefinitely for threads to finish). Following a timeout, a warning will be logged.

Note: properly coded threads should terminate upon interruption but some threads may prove problematic: as the VM does interrupt daemon threads, some code may not have been written to handle interruption properly. For example java.util.Timer is known to not handle interruptions in JDK <= 1.6. So it is not possible for us to infinitely wait by default otherwise maven could hang. A sensible default value has been chosen, but this default value may change in the future based on user feedback.


Default value is: 15000.
executableDependency ExecutableDependency 1.1-beta-1 If provided the ExecutableDependency identifies which of the plugin dependencies contains the executable class. This will have the affect of only including plugin dependencies required by the identified ExecutableDependency.

If includeProjectDependencies is set to true, all of the project dependencies will be included on the executable's classpath. Whether a particular project dependency is a dependency of the identified ExecutableDependency will be irrelevant to its inclusion in the classpath.
includePluginDependencies boolean 1.1-beta-1 Indicates if this plugin's dependencies should be used when executing the main class.

This is useful when project dependencies are not appropriate. Using only the plugin dependencies can be particularly useful when the project is not a java project. For example a mvn project using the csharp plugins only expects to see dotnet libraries as dependencies.
Default value is: false.
includeProjectDependencies boolean 1.1-beta-1 Indicates if the project dependencies should be used when executing the main class.
Default value is: true.
keepAlive boolean 1.0 Deprecated. since 1.1-alpha-1
Default value is: false.
killAfter long 1.0 Deprecated. since 1.1-alpha-1
Default value is: -1.
skip boolean 1.0.1 Skip the execution.
Default value is: false.
sourceRoot File 1.0 This folder is added to the list of those folders containing source to be compiled. Use this if your plugin generates source code.
stopUnresponsiveDaemonThreads boolean 1.1-beta-1 Wether to call Thread.stop() following a timing out of waiting for an interrupted thread to finish. This is only taken into account if cleanupDaemonThreads is true and the daemonThreadJoinTimeout threshold has been reached for an uncooperative thread. If this is false, or if Thread.stop() fails to get the thread to stop, then a warning is logged and Maven will continue on while the affected threads (and related objects in memory) linger on. Consider setting this to true if you are invoking problematic code that you can't fix. An example is Timer which doesn't respond to interruption. To have Timer fixed, vote for this bug.
systemProperties Property[] 1.0 A list of system properties to be passed. Note: as the execution is not forked, some system properties required by the JVM cannot be passed here. Use MAVEN_OPTS or the exec:exec instead. See the user guide for more information.
testSourceRoot File 1.0 This folder is added to the list of those folders containing source to be compiled for testing. Use this if your plugin generates test source code.

Parameter Details

arguments:

The class arguments.
  • Type: java.lang.String[]
  • Since: 1.0
  • Required: No
  • Expression: ${exec.arguments}

classpathScope:

Defines the scope of the classpath passed to the plugin. Set to compile,test,runtime or system depending on your needs. Since 1.1.2, the default value is 'runtime' instead of 'compile'.
  • Type: java.lang.String
  • Since: 1.0
  • Required: No
  • Expression: ${exec.classpathScope}
  • Default: runtime

cleanupDaemonThreads:

Wether to interrupt/join and possibly stop the daemon threads upon quitting.
If this is false, maven does nothing about the daemon threads. When maven has no more work to do, the VM will normally terminate any remaining daemon threads.

In certain cases (in particular if maven is embedded), you might need to keep this enabled to make sure threads are properly cleaned up to ensure they don't interfere with subsequent activity. In that case, see daemonThreadJoinTimeout and stopUnresponsiveDaemonThreads for further tuning.

  • Type: boolean
  • Since: 1.1-beta-1
  • Required: No
  • Expression: ${exec.cleanupDaemonThreads} default-value=

commandlineArgs:

Arguments for the executed program
  • Type: java.lang.String
  • Since: 1.0
  • Required: No
  • Expression: ${exec.args}

daemonThreadJoinTimeout:

This defines the number of milliseconds to wait for daemon threads to quit following their interruption.
This is only taken into account if cleanupDaemonThreads is true. A value <=0 means to not timeout (i.e. wait indefinitely for threads to finish). Following a timeout, a warning will be logged.

Note: properly coded threads should terminate upon interruption but some threads may prove problematic: as the VM does interrupt daemon threads, some code may not have been written to handle interruption properly. For example java.util.Timer is known to not handle interruptions in JDK <= 1.6. So it is not possible for us to infinitely wait by default otherwise maven could hang. A sensible default value has been chosen, but this default value may change in the future based on user feedback.

  • Type: long
  • Since: 1.1-beta-1
  • Required: No
  • Expression: ${exec.daemonThreadJoinTimeout}
  • Default: 15000

executableDependency:

If provided the ExecutableDependency identifies which of the plugin dependencies contains the executable class. This will have the affect of only including plugin dependencies required by the identified ExecutableDependency.

If includeProjectDependencies is set to true, all of the project dependencies will be included on the executable's classpath. Whether a particular project dependency is a dependency of the identified ExecutableDependency will be irrelevant to its inclusion in the classpath.
  • Type: org.codehaus.mojo.exec.ExecutableDependency
  • Since: 1.1-beta-1
  • Required: No

includePluginDependencies:

Indicates if this plugin's dependencies should be used when executing the main class.

This is useful when project dependencies are not appropriate. Using only the plugin dependencies can be particularly useful when the project is not a java project. For example a mvn project using the csharp plugins only expects to see dotnet libraries as dependencies.
  • Type: boolean
  • Since: 1.1-beta-1
  • Required: No
  • Expression: ${exec.includePluginDependencies}
  • Default: false

includeProjectDependencies:

Indicates if the project dependencies should be used when executing the main class.
  • Type: boolean
  • Since: 1.1-beta-1
  • Required: No
  • Expression: ${exec.includeProjectDependencies}
  • Default: true

keepAlive:

Deprecated. since 1.1-alpha-1
Indicates if mojo should be kept running after the mainclass terminates. Usefull for serverlike apps with deamonthreads.
  • Type: boolean
  • Since: 1.0
  • Required: No
  • Expression: ${exec.keepAlive}
  • Default: false

killAfter:

Deprecated. since 1.1-alpha-1
Deprecated this is not needed anymore.
  • Type: long
  • Since: 1.0
  • Required: No
  • Expression: ${exec.killAfter}
  • Default: -1

mainClass:

The main class to execute.
  • Type: java.lang.String
  • Since: 1.0
  • Required: Yes
  • Expression: ${exec.mainClass}

skip:

Skip the execution.
  • Type: boolean
  • Since: 1.0.1
  • Required: No
  • Expression: ${skip}
  • Default: false

sourceRoot:

This folder is added to the list of those folders containing source to be compiled. Use this if your plugin generates source code.
  • Type: java.io.File
  • Since: 1.0
  • Required: No
  • Expression: ${sourceRoot}

stopUnresponsiveDaemonThreads:

Wether to call Thread.stop() following a timing out of waiting for an interrupted thread to finish. This is only taken into account if cleanupDaemonThreads is true and the daemonThreadJoinTimeout threshold has been reached for an uncooperative thread. If this is false, or if Thread.stop() fails to get the thread to stop, then a warning is logged and Maven will continue on while the affected threads (and related objects in memory) linger on. Consider setting this to true if you are invoking problematic code that you can't fix. An example is Timer which doesn't respond to interruption. To have Timer fixed, vote for this bug.
  • Type: boolean
  • Since: 1.1-beta-1
  • Required: No
  • Expression: ${exec.stopUnresponsiveDaemonThreads} default-value=

systemProperties:

A list of system properties to be passed. Note: as the execution is not forked, some system properties required by the JVM cannot be passed here. Use MAVEN_OPTS or the exec:exec instead. See the user guide for more information.
  • Type: org.codehaus.mojo.exec.Property[]
  • Since: 1.0
  • Required: No

testSourceRoot:

This folder is added to the list of those folders containing source to be compiled for testing. Use this if your plugin generates test source code.
  • Type: java.io.File
  • Since: 1.0
  • Required: No
  • Expression: ${testSourceRoot}