if (mavenLog) {
System.setProperty("openejb.log.factory", MavenLogStreamFactory.class.getName()); // this line also preload the class (<cinit>)
System.setProperty("openejb.jul.forceReload", "true");
}
final Container container = new Container();
final Configuration config = getConfig();
container.setup(config);
final Thread hook = new Thread() {
@Override
public void run() {
if (container.getTomcat() != null && container.getTomcat().getServer().getState() != LifecycleState.DESTROYED) {
try {
if (!classpathAsWar) {
container.undeploy(warFile.getAbsolutePath());
}
container.stop();
} catch (final Exception e) {
getLog().error("can't stop TomEE", e);
}
}
}
};
try {
container.start();
SystemInstance.get().setComponent(ParentClassLoaderFinder.class, new ProvidedClassLoaderFinder(loader));
Runtime.getRuntime().addShutdownHook(hook);
if (!classpathAsWar) {
container.deploy('/' + (context == null ? warFile.getName() : context), warFile, true);
} else {
if (useProjectClasspath) {
thread.setContextClassLoader(createClassLoader(loader));
}
container.deployClasspathAsWebApp(context, docBase); // null is handled properly so no issue here
}
getLog().info("TomEE embedded started on " + config.getHost() + ":" + config.getHttpPort());
} catch (Exception e) {
getLog().error("can't start TomEE", e);
}
try {
String line;
final Scanner scanner = new Scanner(System.in);
while ((line = scanner.nextLine()) != null) {
switch (line.trim()) {
case "exit":
case "quit":
Runtime.getRuntime().removeShutdownHook(hook);
container.close();
return;
}
}
} catch (final Exception e) {
Thread.interrupted();