in tooling/camel-karaf-maven-plugin/src/main/java/org/apache/camel/maven/KarafRunMojo.java [365:443]
public void execute() throws MojoExecutionException, MojoFailureException {
List<String> args = parseArguments();
arguments = new String[args.size()];
args.toArray(arguments);
if (getLog().isDebugEnabled()) {
StringBuilder msg = new StringBuilder("Invoking: ");
msg.append(mainClass);
msg.append(".main(");
for (int i = 0; i < arguments.length; i++) {
if (i > 0) {
msg.append(", ");
}
msg.append(arguments[i]);
}
msg.append(")");
getLog().debug(msg);
}
final ClassLoader loader = getClassLoader();
KarafRunMojo.IsolatedThreadGroup threadGroup = new KarafRunMojo.IsolatedThreadGroup(mainClass /* name */);
final Thread bootstrapThread = new Thread(threadGroup, new Runnable() {
public void run() {
try {
beforeBootstrapCamel();
getLog().info("Starting Camel ...");
Method main = Thread.currentThread().getContextClassLoader()
.loadClass(mainClass).getMethod("main", String[].class);
main.invoke(null, new Object[] { arguments });
afterBootstrapCamel();
} 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);
}
}
}, mainClass + ".main()");
bootstrapThread.setContextClassLoader(loader);
setSystemProperties();
bootstrapThread.start();
joinNonDaemonThreads(threadGroup);
// It's plausible that spontaneously a non-daemon thread might be
// created as we try and shut down,
// but it's too late since the termination condition (only daemon
// threads) has been triggered.
if (keepAlive) {
getLog().warn("Warning: keepAlive is now deprecated and obsolete. Do you need it? Please comment on MEXEC-6.");
waitFor(0);
}
if (cleanupDaemonThreads) {
terminateThreads(threadGroup);
try {
threadGroup.destroy();
} catch (IllegalThreadStateException e) {
getLog().warn("Couldn't destroy threadgroup " + threadGroup, e);
}
}
if (originalSystemProperties != null) {
System.setProperties(originalSystemProperties);
}
synchronized (threadGroup) {
if (threadGroup.uncaughtException != null) {
throw new MojoExecutionException(null, threadGroup.uncaughtException);
}
}
registerSourceRoots();
}