JavaExecMojo
. main
, mojo. , , jvm.
, maven exec. ExecJavaMojo.
JavaExecMojo
Thread.currentThread().getThreadGroup().uncaughtException( Thread.currentThread(), e );
. , uncaughtException
ThreadGroup
JVM , . . Javadoc ThreadGroup.uncaughtException( t, Throwable e).
Java, - , Thread.UncaughtExceptionHandler, .
,
try {
....
} catch (Exception e) {
Thread currentThread = Thread.currentThread();
Thread.UncaughtExceptionHandler ueh = currentThread.getUncaughtExceptionHandler();
if (ueh == null) {
currentThread.getThreadGroup().uncaughtException(currentThread, e);
} else {
ueh.uncaughtException(currentThread, e);
}
}
JVM.
defaultUncaughtExceptionHandler
.
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
System.out.println("Handled exception - let log it!");
}
});
defaultUncaughtExceptionHandler java.lang.reflect.InvocationTargetException.
. . ThreadGroup
. . IsolatedThreadGroup
class IsolatedThreadGroup extends ThreadGroup {
private Throwable uncaughtException;
public IsolatedThreadGroup( String name ){
super( name );
}
public void uncaughtException( Thread thread, Throwable throwable ) {
if ( throwable instanceof ThreadDeath ) {
return;
}
synchronized ( this ) {
if ( uncaughtException == null ) {
uncaughtException = throwable;
}
}
getLog().warn( throwable );
}
}
javadoc uncaughtException
,
uncaughtException ThreadGroup :
- , uncaughtException .
- , , , uncaughtException .
- , Throwable ThreadDeath. , . , , getName , , Throwable printStackTrace, .
, api. defaultUncaughtExceptionHandler
.
JavaExecMojo
. ExecMojo
. .
mvn exec:exec -Dexec.executable="java" -Dexec.workingdir="someDir" -Dexec.args="-cp target/classes"
pom, . .
<workingdir>${basedir}</workingdir>
<args>-cp ${project.build.outputDirectory}</args>