Details
Description
If java.lang.management is due to security reasons (or anything else) not part of the JVM, we need so set the JVM Property -Dlog4j2.jmx.disable=true.
The initialization of the JVM is fine, as the JMX Server class verifies if JMX is disabled. The Problem is as soon as log4j shuts down, it tries to unregister JMX and ends up with a NoClassDefFoundError, thus log4j exits abnormally.
Server.java
public static void reregisterMBeansAfterReconfigure() { // avoid creating Platform MBean Server if JMX disabled if (isJmxDisabled()) { LOGGER.debug("JMX disabled for log4j2. Not registering MBeans."); return; } final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); reregisterMBeansAfterReconfigure(mbs); } public static void unregisterLoggerContext(final String loggerContextName) { final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); unregisterLoggerContext(loggerContextName, mbs); }
2016-08-09 18:54:06,512 pool-1-thread-1 ERROR Caught exception executing shutdown hook Shutdown callback for LoggerContext[name=4ee00c09] java.lang.NoClassDefFoundError: java/lang/management/ManagementFactory at org.apache.logging.log4j.core.jmx.Server.unregisterLoggerContext(Server.java:236) at org.apache.logging.log4j.core.LoggerContext.stop(LoggerContext.java:300) at org.apache.logging.log4j.core.LoggerContext$1.run(LoggerContext.java:265) at org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry$RegisteredCancellable.run(DefaultShutdownCallbackRegistry.java:102) at org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry.run(DefaultShutdownCallbackRegistry.java:72) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.ClassNotFoundException: java.lang.management.ManagementFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 6 more }