ApplicationIntrospector { static Class<?> mainClass() { for (Map.Entry<Thread, StackTraceElement[]> stackEntry : Thread.getAllStackTraces().entrySet()) { if ("main".equals(stackEntry.getKey().getName())) { StackTraceElement[] stack = stackEntry.getValue(); StackTraceElement bottom = stack[stack.length - 1]; if ("main".equals(bottom.getMethodName())) { try { return Class.forName(bottom.getClassName()); } catch (ClassNotFoundException e) { return Bootique.class; } } else { return Bootique.class; } } } return Bootique.class; }    }
@Test public void testMainClass() { Class<?> mainClass = ApplicationIntrospector.mainClass(); assertNotNull(mainClass); assertNotEquals(Bootique.class, mainClass); }