System.setProperty(entry.getKey(), entry.getValue());
}
getLog().info("Adding system properties: " + systemProperties);
}
final IsolatedThreadGroup threadGroup = new IsolatedThreadGroup(this, mainClass);
final Thread bootstrapThread = new Thread(threadGroup, new Runnable() {
public void run() {
try {
beforeBootstrapHawtio();
getLog().info("Starting hawtio ...");
getLog().info("*************************************");
Method hawtioMain = Thread.currentThread().getContextClassLoader().loadClass("io.hawt.app.App")
.getMethod("main", String[].class);
String[] args = new String[]{"--context", context, "--port", "" + port};
hawtioMain.invoke(null, new Object[]{args});
afterBootstrapHawtio();
beforeBootstrapMain();
if (bootstrapMain) {
getLog().info("Starting " + mainClass + "...");
getLog().info("*************************************");
Method main = Thread.currentThread().getContextClassLoader().loadClass(mainClass)
.getMethod("main", String[].class);
main.invoke(main, new Object[] {arguments});
}
afterBootstrapMain();
} catch (Exception e) { // just pass it on
// let it be printed so end users can see the exception on the console
getLog().error("*************************************");
getLog().error("Error occurred while running main from: " + mainClass);
getLog().error(e);
getLog().error("*************************************");
Thread.currentThread().getThreadGroup().uncaughtException(Thread.currentThread(), e);
}
// notify before we die
getLog().info("Terminating thread " + Thread.currentThread());
}
}, mainClass + ".main()");
// resolve artifacts to be used
Set<Artifact> artifacts = resolveArtifacts();
resolvedArtifacts(artifacts);
classLoader = getClassLoader(artifacts);
bootstrapThread.setContextClassLoader(classLoader);
bootstrapThread.start();
mojoLifecycle.join(threadGroup);
try {
getLog().info("We will now terminate thread group " + threadGroup);
mojoLifecycle.terminateThreads(threadGroup);
threadGroup.destroy();
} catch (IllegalThreadStateException e) {
getLog().warn("Cannot destroy thread group " + threadGroup, e);
}
if (threadGroup.getUncaughtException() != null) {
throw new MojoExecutionException("Uncaught exception", threadGroup.getUncaughtException());
}
}