19

[error] p.c.s.n.PlayRequestHandler - Exception caught in Netty java.lang.NoClassDefFoundError: Could not initialize class play.api.http.DefaultHttpErrorHandler$ at

I get error message and my app doesn't start in dev mode.

The error doesn't give me any details about what went wrong. I changed log level in logback.xml to DEBUG, but it didn't help.

Any suggestions how to investigate the problem? A week ago it worked just fine and since then there was no any changes in sources and configuration. It stopped working for an unknown reason.

Edit1: How do I enable more verbose logging? Otherwise it's absolutely unclear where the error comes from.

Edit2: changed the title

 (Server started, use Ctrl+D to stop and go back to the console...)

  Warning: node.js detection failed, sbt will use the Rhino based Trireme JavaScript engine instead to run JavaScript assets compilation, which in some cases may be orders of magnitude slower than using no
  de.js.
  [error] p.c.s.n.PlayRequestHandler - Exception caught in Netty
  java.lang.NoClassDefFoundError: Could not initialize class play.api.http.DefaultHttpErrorHandler$
          at play.core.server.Server$class.logExceptionAndGetResult$1(Server.scala:45)
          at play.core.server.Server$class.getHandlerFor(Server.scala:65)
          at play.core.server.NettyServer.getHandlerFor(NettyServer.scala:47)
          at play.core.server.netty.PlayRequestHandler.handle(PlayRequestHandler.scala:82)
          at play.core.server.netty.PlayRequestHandler.channelRead(PlayRequestHandler.scala:163)
          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)
          at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278)
          at com.typesafe.netty.http.HttpStreamsHandler.channelRead(HttpStreamsHandler.java:129)
          at com.typesafe.netty.http.HttpStreamsServerHandler.channelRead(HttpStreamsServerHandler.java:96)
          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)
  [error] p.c.s.n.PlayRequestHandler - Exception caught in Netty
  java.lang.NoClassDefFoundError: Could not initialize class play.api.http.DefaultHttpErrorHandler$
          at play.core.server.Server$class.logExceptionAndGetResult$1(Server.scala:45)
          at play.core.server.Server$class.getHandlerFor(Server.scala:65)
          at play.core.server.NettyServer.getHandlerFor(NettyServer.scala:47)
          at play.core.server.netty.PlayRequestHandler.handle(PlayRequestHandler.scala:82)
          at play.core.server.netty.PlayRequestHandler.channelRead(PlayRequestHandler.scala:163)
          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)
          at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278)
          at com.typesafe.netty.http.HttpStreamsHandler.channelRead(HttpStreamsHandler.java:129)
          at com.typesafe.netty.http.HttpStreamsServerHandler.channelRead(HttpStreamsServerHandler.java:96)
          at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)
Mike Pakhomov
  • 425
  • 6
  • 14
  • [this question might help](http://stackoverflow.com/questions/31491931/warning-node-js-detection-failed-sbt-will-use-the-rhino-based-trireme-javascri) also I do think that the first line is very clear. – AME May 10 '16 at 13:41
  • @PiNg2Eiw yes, that one is clear. but it's just a warning. I need to figure out why I get p.c.s.n.PlayRequestHandler - Exception caught in Netty – Mike Pakhomov May 10 '16 at 14:12
  • Have you tried 'sbt clean'? – rethab May 10 '16 at 14:16
  • @rethab. Yes I have. Besides that, I have deleted all build files manually. Still, no luck. – Mike Pakhomov May 10 '16 at 14:44
  • Are you starting your server using `activator run`? – kag0 Aug 18 '16 at 00:51

4 Answers4

39

I don't know exactly what your problem is, but I encountered this cryptic, unhelpful error when I discovered an error in my application.conf where I was attempting to set a configuration based on an environment variable that may or may not be there. Clearly, the cause of the exception and the place it becomes apparent are pretty far apart.

So I would suggest checking your application.conf for a misconfiguration. Consider also any dependencies that might have been built for Play versions < 2.5. Basically anything that might cause the application to be "mis-initalized" for lack of a better term.

EDIT: I just discovered another cause of this error that falls under the category of "mis-initialization." I changed the name of a route in my routes file but forgot to change the corresponding reverse route in my template. I feel this should be caught sooner and with a more intuitive error, but regardless, look out for this (or something similar) as well in application.conf or routes.

Vidya
  • 29,932
  • 7
  • 42
  • 70
  • Hit that just now as I migrated from 2.4 to 2.5 and it was a mistyped (mis-cased) string (class name) in application.conf for me. – Techmag May 11 '16 at 21:12
  • 1
    Confirmed : I tried to add a global environment variable to application.conf and this will just crash the Play app if you don't set this variable. – N.Martignole Jun 12 '16 at 13:33
  • 1
    confirmed: any typo in application.conf causes this error. check each parameter value is like "value" – Yilmaz Guleryuz Aug 02 '16 at 17:48
  • 3
    Confirmed as well. In my case, the specific problem is that I was trying to do an environment variable override via ${?ENV_VAR} but forgot the question mark. – David Nov 26 '16 at 17:57
13

Oops.. java.lang.NoClassDefFoundError: Could not initialize class play.api.http.DefaultHttpErrorHandler$ tells nothing what went wrong. One such reason I have encountered is when I had missing/typos in my configuration properties and use guice injectors.

You can run your app in prod mode to see more informative error message activator clean compile start.

....

[info] Done packaging.

(Starting server. Type Ctrl+D to exit logs, the server will remain in background)

Oops, cannot start the server. Configuration error: Configuration error[storage.conf @ file:/myproject/mymodule/target/universal/stage/conf/storage.conf: 16: Could not resolve substitution to a value: ${storage.cluster.name}] at play.api.Configuration$.configError(Configuration.scala:154) ....

Deepak
  • 214
  • 1
  • 2
  • 9
0

In my case the below dependency was what was causing the error

libraryDependencies += "com.google.cloud" % "gcloud-java-storage" % "0.2.5"

Source Getting ChannelException when adding Google cloud client library to Play 2.5

Community
  • 1
  • 1
binshi
  • 1,248
  • 2
  • 17
  • 33
0

In my case it was a missed } in the application.conf file :( .

Yuliban
  • 143
  • 7