NoClassDefFoundError: ch/qos/logback/core/LifeCycleManager
We create a java play project with sbt new playframework/play-java-seed.g8
Then we add play-ebean as dependency in project/plugins.sbt
addSbtPlugin("com.typesafe.play" % "sbt-play-ebean" % "6.2.0-RC7")
and build.sbt
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
Add shutdown hook in logback.xml
<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook" />
When the project process one request and we press Enter to stop the project got this exception.
Exception in thread "Logback shutdown hook [default]" Exception in thread "Logback shutdown hook [default]" java.lang.NoClassDefFoundError: ch/qos/logback/core/LifeCycleManager
at ch.qos.logback.core.ContextBase.getLifeCycleManager(ContextBase.java:260)
at ch.qos.logback.core.ContextBase.reset(ContextBase.java:175)
at ch.qos.logback.classic.LoggerContext.reset(LoggerContext.java:220)
at ch.qos.logback.classic.LoggerContext.stop(LoggerContext.java:348)
at ch.qos.logback.core.hook.ShutdownHookBase.stop(ShutdownHookBase.java:39)
at ch.qos.logback.core.hook.DelayingShutdownHook.run(DelayingShutdownHook.java:57)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.LifeCycleManager
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 7 more
Thanks.
@hedecai Why do you add the shutdown hook? AFAIK Play actually already does takes care of that and shuts down logback.
Actually I also think this problem is a classloder problem, probably only occuring in dev mode.
@mkurz From the play document https://www.playframework.com/documentation/2.8.x/SettingsLogger the play production default configuration has a shutdownHook. Remove the shutdownHook from config is ok?
Remove the shutdownHook from config is ok?
Yes, absolutely. Actually you definitely should remove it from you config. It makes things even worse, that's why I will remove it from the documentation, see https://github.com/playframework/playframework/pull/11532
Why there is a NoClassDefFoundError is a different story, which I have no answer to right now. Either it's related to https://github.com/playframework/playframework/pull/10939 or the sbt play-ebean plugin messes around with the classloader too much (looking at https://github.com/playframework/play-ebean/blob/6.2.x/sbt-play-ebean/src/main/scala-sbt-1.0/play/ebean/sbt/PlayEbean.scala it does set/unset the classloader and other kung-fu) Anyway, I will not look into this.
So your problem is solved by just not adding <shutdownHook />to your config.