Class ExecJavaMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class
a ThreadGroup to isolate execution and collect exceptions. -
Field Summary
FieldsModifier and TypeFieldDescriptionAdditional elements to be appended to the classpath.private String[]
The class arguments.private boolean
Whether to interrupt/join and possibly stop the daemon threads upon quitting.private long
This defines the number of milliseconds to wait for daemon threads to quit following their interruption.
This is only taken into account ifcleanupDaemonThreads
istrue
.private org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver
private boolean
Indicates if this plugin's dependencies should be used when executing the main class.private boolean
Indicates if the project dependencies should be used when executing the main class.private boolean
Deprecated.since 1.1-alpha-1private long
Deprecated.since 1.1-alpha-1private String
The main class to execute.
With Java 9 and above you can prefix it with the modulename, e.g.private Properties
private List
<org.apache.maven.artifact.Artifact> private org.apache.maven.project.ProjectBuilder
private boolean
Wether to callThread.stop()
following a timing out of waiting for an interrupted thread to finish.private Property[]
A list of system properties to be passed.Fields inherited from class org.codehaus.mojo.exec.AbstractExecMojo
classpathScope, executableDependency, project
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
private void
Add any relevant project dependencies to the classpath.private void
Add any relevant project dependencies to the classpath.private Set
<org.apache.maven.artifact.Artifact> Determine all plugin dependencies relevant to the executable.void
execute()
Execute goal.private Collection
<Thread> getActiveThreads
(ThreadGroup threadGroup) private ClassLoader
Set up a classloader for the execution of the main class.private void
joinNonDaemonThreads
(ThreadGroup threadGroup) private void
joinThread
(Thread thread, long timeoutMsecs) private Set
<org.apache.maven.artifact.Artifact> resolveExecutableDependencies
(org.apache.maven.artifact.Artifact executablePomArtifact) Resolve the executable dependencies for the specified projectprivate void
Pass any given system properties to the java system properties.private void
terminateThreads
(ThreadGroup threadGroup) private void
waitFor
(long millis) Stop program execution for nn millis.Methods inherited from class org.codehaus.mojo.exec.AbstractExecMojo
collectProjectArtifactsAndClasspath, findExecutableArtifact, getSession, hasCommandlineArgs, isSkip, parseCommandlineArgs, registerSourceRoots
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
dependencyResolver
@Component private org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver dependencyResolver -
projectBuilder
@Component private org.apache.maven.project.ProjectBuilder projectBuilder- Since:
- 1.0
-
pluginDependencies
@Parameter(readonly=true, defaultValue="${plugin.artifacts}") private List<org.apache.maven.artifact.Artifact> pluginDependencies- Since:
- 1.1-beta-1
-
mainClass
The main class to execute.
With Java 9 and above you can prefix it with the modulename, e.g.com.greetings/com.greetings.Main
Without modulename the classpath will be used, with modulename a new modulelayer will be created.- Since:
- 1.0
-
arguments
The class arguments.- Since:
- 1.0
-
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.- Since:
- 1.0
-
keepAlive
Deprecated.since 1.1-alpha-1Indicates if mojo should be kept running after the mainclass terminates. Use full for server like apps with daemon threads.- Since:
- 1.0
-
includeProjectDependencies
@Parameter(property="exec.includeProjectDependencies", defaultValue="true") private boolean includeProjectDependenciesIndicates if the project dependencies should be used when executing the main class.- Since:
- 1.1-beta-1
-
includePluginDependencies
@Parameter(property="exec.includePluginsDependencies", defaultValue="false") private boolean includePluginDependenciesIndicates 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.- Since:
- 1.1-beta-1
-
cleanupDaemonThreads
@Parameter(property="exec.cleanupDaemonThreads", defaultValue="true") private boolean cleanupDaemonThreadsWhether to interrupt/join and possibly stop the daemon threads upon quitting.
If this isfalse
, 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
andstopUnresponsiveDaemonThreads
for further tuning.- Since:
- 1.1-beta-1
-
daemonThreadJoinTimeout
@Parameter(property="exec.daemonThreadJoinTimeout", defaultValue="15000") private long daemonThreadJoinTimeoutThis defines the number of milliseconds to wait for daemon threads to quit following their interruption.
This is only taken into account ifcleanupDaemonThreads
istrue
. 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.
- Since:
- 1.1-beta-1
-
stopUnresponsiveDaemonThreads
@Parameter(property="exec.stopUnresponsiveDaemonThreads", defaultValue="false") private boolean stopUnresponsiveDaemonThreadsWether to callThread.stop()
following a timing out of waiting for an interrupted thread to finish. This is only taken into account ifcleanupDaemonThreads
istrue
and thedaemonThreadJoinTimeout
threshold has been reached for an uncooperative thread. If this isfalse
, or ifThread.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 totrue
if you are invoking problematic code that you can't fix. An example isTimer
which doesn't respond to interruption. To haveTimer
fixed, vote for this bug.- Since:
- 1.1-beta-1
-
killAfter
Deprecated.since 1.1-alpha-1Deprecated this is not needed anymore.- Since:
- 1.0
-
originalSystemProperties
-
additionalClasspathElements
Additional elements to be appended to the classpath.- Since:
- 1.3
-
-
Constructor Details
-
ExecJavaMojo
public ExecJavaMojo()
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureExceptionExecute goal.- Throws:
org.apache.maven.plugin.MojoExecutionException
- execution of the main class or one of the threads it generated failed.org.apache.maven.plugin.MojoFailureException
- something bad happened...
-
joinNonDaemonThreads
-
joinThread
-
terminateThreads
-
getActiveThreads
-
setSystemProperties
private void setSystemProperties()Pass any given system properties to the java system properties. -
getClassLoader
Set up a classloader for the execution of the main class.- Returns:
- the classloader
- Throws:
org.apache.maven.plugin.MojoExecutionException
- if a problem happens
-
addAdditionalClasspathElements
-
addRelevantPluginDependenciesToClasspath
private void addRelevantPluginDependenciesToClasspath(List<Path> path) throws org.apache.maven.plugin.MojoExecutionException Add any relevant project dependencies to the classpath. Indirectly takes includePluginDependencies and ExecutableDependency into consideration.- Parameters:
path
- classpath ofURL
objects- Throws:
org.apache.maven.plugin.MojoExecutionException
- if a problem happens
-
addRelevantProjectDependenciesToClasspath
private void addRelevantProjectDependenciesToClasspath(List<Path> path) throws org.apache.maven.plugin.MojoExecutionException Add any relevant project dependencies to the classpath. Takes includeProjectDependencies into consideration.- Parameters:
path
- classpath ofURL
objects- Throws:
org.apache.maven.plugin.MojoExecutionException
- if a problem happens
-
determineRelevantPluginDependencies
private Set<org.apache.maven.artifact.Artifact> determineRelevantPluginDependencies() throws org.apache.maven.plugin.MojoExecutionExceptionDetermine all plugin dependencies relevant to the executable. Takes includePlugins, and the executableDependency into consideration.- Returns:
- a set of Artifact objects. (Empty set is returned if there are no relevant plugin dependencies.)
- Throws:
org.apache.maven.plugin.MojoExecutionException
- if a problem happens resolving the plufin dependencies
-
resolveExecutableDependencies
private Set<org.apache.maven.artifact.Artifact> resolveExecutableDependencies(org.apache.maven.artifact.Artifact executablePomArtifact) throws org.apache.maven.plugin.MojoExecutionException Resolve the executable dependencies for the specified project- Parameters:
executablePomArtifact
- the project's POM- Returns:
- a set of Artifacts
- Throws:
org.apache.maven.plugin.MojoExecutionException
- if a failure happens
-
waitFor
private void waitFor(long millis) Stop program execution for nn millis.- Parameters:
millis
- the number of millis-seconds to wait for,0
stops program forever.
-