play-ebean icon indicating copy to clipboard operation
play-ebean copied to clipboard

NoClassDefFoundError: ch/qos/logback/core/LifeCycleManager

Open hedecai opened this issue 3 years ago • 3 comments

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 avatar Jul 27 '22 02:07 hedecai

@hedecai Why do you add the shutdown hook? AFAIK Play actually already does takes care of that and shuts down logback.

mkurz avatar Aug 08 '22 08:08 mkurz

Actually I also think this problem is a classloder problem, probably only occuring in dev mode.

mkurz avatar Aug 08 '22 08:08 mkurz

@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?

hedecai avatar Aug 10 '22 12:08 hedecai

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.

mkurz avatar Nov 10 '22 20:11 mkurz