Exception caught in Netty in play framework - scala

I have created a new play framework app in SCALA. If i run the application it runs as expected and i am able to open the URL localhost:9000, but after i created a lib folder and added some jars(spark jars) in that when i tries to run the application using the command play run, it shows the message
[error] p.nettyException - Exception caught in Netty
java.lang.NoSuchMethodError: scala.collection.immutable.HashSet$.empty()Lscala/collection/immutable/HashSet;
at akka.actor.ActorCell$.<init>(ActorCell.scala:305) ~[akka-actor_2.10.jar:2.2.0]
at akka.actor.ActorCell$.<clinit>(ActorCell.scala) ~[akka-actor_2.10.jar:2.2.0]
at akka.actor.RootActorPath.$div(ActorPath.scala:152) ~[akka-actor_2.10.jar:2.2.0]
at akka.actor.LocalActorRefProvider.<init>(ActorRefProvider.scala:465) ~[akka-actor_2.10.jar:2.2.0]
at akka.actor.LocalActorRefProvider.<init>(ActorRefProvider.scala:453) ~[akka-actor_2.10.jar:2.2.0]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_91]
[error] p.nettyException - Exception caught in Netty
java.lang.NoClassDefFoundError: Could not initialize class play.api.libs.concurrent.Execution$
when i tries to open the URL localhost:9000 it shows "localhost page is not working".
Spark Version 2.0
Scala Version 2.10 and also i have tested with scala 2.11 and 2.12 same error reproducing.
Play framework version - 2.2.6

First, if you created a new Play! project, why use version 2.2? The newest one is 2.5 and that may already fix your issue.
Second, to ensure you don't have any other version conflicts I suggest you use managed dependencies instead of putting them manually into the lib folder.
For Apache Spark, you would add this line to your build.sbt file:
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.1.0"
as described in Spark's Quick Start Guide. You need to use Scala 2.10 or 2.11 (suggested) in your project.
If that doesn't resolve your issue, please post the contents of your build.sbt and the controller code. Thanks.

Related

getting NoClassDefFoundError using elastic4s

I'm using play 2.6 and scala 2.12 in my app, and elastic search using elastic4s.
In my build.sbt:
"com.sksamuel.elastic4s" %% "elastic4s-core" % "5.6.0",
"com.sksamuel.elastic4s" %% "elastic4s-http" % "5.6.0",
and I keep getting this exception in my log:
Exception in thread "I/O dispatcher 16" java.lang.NoClassDefFoundError: Could not initialize class com.sksamuel.elastic4s.http.JacksonSupport$
at com.sksamuel.elastic4s.http.ResponseHandler$.fromEntity(ResponseHandler.scala:47)
at com.sksamuel.elastic4s.http.DefaultResponseHandler.$anonfun$onResponse$1(ResponseHandler.scala:55)
at scala.util.Try$.apply(Try.scala:209)
at com.sksamuel.elastic4s.http.DefaultResponseHandler.onResponse(ResponseHandler.scala:55)
at com.sksamuel.elastic4s.http.HttpExecutable$RichRestClient$$anon$1.onSuccess(HttpExecutable.scala:27)
at org.elasticsearch.client.RestClient$FailureTrackingResponseListener.onSuccess(RestClient.java:597)
at org.elasticsearch.client.RestClient$1.completed(RestClient.java:352)
at org.elasticsearch.client.RestClient$1.completed(RestClient.java:343)
at org.apache.http.concurrent.BasicFuture.completed(BasicFuture.java:119)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseCompleted(DefaultClientExchangeHandlerImpl.java:177)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:436)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:326)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:265)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114)
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588)
at java.lang.Thread.run(Thread.java:748)
Trying to figure out what could cause this.
In another log also saw:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Scala module 2.8.8 requires Jackson Databind version >= 2.8.0 and < 2.9.0
so it looks like something with the jackson version, or also with the jackson version, but not sure where do I update it or where is it failing exactly...
Someone ever had this issue?
thanks!
Double check if you are importing elastic4s-jackson:
libraryDependencies += "com.sksamuel.elastic4s" %% "elastic4s-jackson" % "5.6.0"
I have had the exact same issue with play 2.8 and elastic4s 6.7.3 using the jackson module too
What helped me was running evicted and looking at the dependencies each library had and figuring out why it cannot load that particular class . ultimately upgrading to 6.7.8 ended up resolving the issue.
Also if you look in the buid.sbt file for the elasic4s project it lists all the versions it is using https://github.com/sksamuel/elastic4s/blob/master/build.sbt
You can use jackson-module-scala and exclude the com.fasterxml.jackson which is referenced in elastic4s-http and verify that com.fasterxml.jackson is available in the libraries/classpath when the application is running.

Exception in Play Framework 2.6

I Was using play framework 2.5.
My scala version is 2.11.8.
When I migrated to Paly 2.6, I'm getting the following error
RuntimeException: java.lang.NoClassDefFoundError: play/api/libs/ws/WSRequest$class
WS was extracted to it's own library, so you need to add in the build.sbt:
libraryDependencies += ws
You can find more details in the official documentation: https://www.playframework.com/documentation/2.6.x/ScalaWS
And do not forget the migration guide:
https://www.playframework.com/documentation/2.6.x/WSMigration26

Using Gephi inside a Play Application

I am currently building a Play Framework application in Scala that requires the use of the Gephi Java library.
I tried adding Gephi as a managed dependency in SBT, but SBT cannot resolve all of Gephi's dependencies. This is a known issue. I then simply tried to add the whole Gephi JAR in my lib/ folder as an unmanaged dependency. IntelliJ detects the library just fine and I can compile my application perfectly fine. The problem is an exception occurs immediately upon starting the application, and it seems to be related to dependency injection:
play.api.UnexpectedException: Unexpected exception[NoSuchMethodError: com.google.common.base.Objects.firstNonNull(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:174)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:126)
at scala.Option.map(Option.scala:146)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:126)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:124)
at scala.util.Success.flatMap(Try.scala:231)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:124)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:116)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
Caused by: java.lang.NoSuchMethodError: com.google.common.base.Objects.firstNonNull(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
at com.google.common.cache.CacheBuilder.getKeyStrength(CacheBuilder.java:529)
at com.google.common.cache.LocalCache.<init>(LocalCache.java:242)
at com.google.common.cache.LocalCache$LocalManualCache.<init>(LocalCache.java:4718)
at com.google.common.cache.CacheBuilder.build(CacheBuilder.java:807)
at com.google.inject.internal.WeakKeySet.<init>(WeakKeySet.java:55)
at com.google.inject.internal.InheritingState.<init>(InheritingState.java:67)
at com.google.inject.internal.InjectorShell$Builder.getState(InjectorShell.java:209)
at com.google.inject.internal.InjectorShell$Builder.lock(InjectorShell.java:115)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
at com.google.inject.Guice.createInjector(Guice.java:96)
I tried removing all mention of Gephi in the code, while still having the JAR sitting in my lib/ folder, but it results in the same exception.
Gephi is really important for this project, so I can't just move on to another library. Any ideas?
Remove that jar fom lib, add those two additional resolvers (in build.sbt)
resolvers += "NetBeans" at "http://bits.netbeans.org/nexus/content/groups/netbeans/"
resolvers += "gephi" at "https://raw.github.com/gephi/gephi/mvn-thirdparty-repo/"
and run activator update

java.lang.NoClassDefFoundError: scala/reflect/api/TypeCreator

I'm getting this error message when I run my sbt project in IntelliJ by right clicking "Debug".
/home/johnreed/Applications/jdk1.8.0_73/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:34395,suspend=y,server=n -Dfile.encoding=UTF-8 -classpath /home/johnreed/Applications/jdk1.8.0_73/jre/lib/charsets.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/deploy.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/cldrdata.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/dnsns.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/jaccess.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/jfxrt.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/localedata.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/nashorn.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/sunec.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/sunjce_provider.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/sunpkcs11.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/ext/zipfs.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/javaws.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/jce.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/jfr.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/jfxswt.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/jsse.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/management-agent.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/plugin.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/resources.jar:/home/johnreed/Applications/jdk1.8.0_73/jre/lib/rt.jar:/home/johnreed/sbtProjects/UnderstandingScala/target/scala-2.11/classes:/home/johnreed/.ivy2/cache/com.chuusai/shapeless_2.11/bundles/shapeless_2.11-2.3.1.jar:/home/johnreed/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.8.jar:/home/johnreed/.ivy2/cache/com.google.code.findbugs/jsr305/jars/jsr305-2.0.1.jar:/home/johnreed/.ivy2/cache/com.google.guava/guava/bundles/guava-16.0.1.jar:/home/johnreed/.ivy2/cache/com.twitter/jsr166e/jars/jsr166e-1.0.0.jar:/home/johnreed/.ivy2/cache/com.twitter/util-collection_2.11/jars/util-collection_2.11-6.34.0.jar:/home/johnreed/.ivy2/cache/com.twitter/util-core_2.11/jars/util-core_2.11-6.34.0.jar:/home/johnreed/.ivy2/cache/com.twitter/util-function_2.11/jars/util-function_2.11-6.34.0.jar:/home/johnreed/.ivy2/cache/commons-collections/commons-collections/jars/commons-collections-3.2.2.jar:/home/johnreed/.ivy2/cache/javax.inject/javax.inject/jars/javax.inject-1.jar:/home/johnreed/.ivy2/cache/org.scala-lang.modules/scala-parser-combinators_2.11/bundles/scala-parser-combinators_2.11-1.0.4.jar:/home/johnreed/.ivy2/cache/org.typelevel/macro-compat_2.11/jars/macro-compat_2.11-1.1.1.jar:/home/johnreed/.ivy2/cache/scala.trace/scala-trace-debug_2.11/jars/scala-trace-debug_2.11-2.2.14.jar:/home/johnreed/Applications/idea-IC-145.258.11/lib/idea_rt.jar pkg.Main
Connected to the target VM, address: '127.0.0.1:34395', transport: 'socket'
Disconnected from the target VM, address: '127.0.0.1:34395', transport: 'socket'
Exception in thread "main" java.lang.NoClassDefFoundError: scala/reflect/api/TypeCreator
at pkg.Main.main(Main.scala)
Caused by: java.lang.ClassNotFoundException: scala.reflect.api.TypeCreator
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
Process finished with exit code 1
I only get this error when I run from IntelliJ. When I run it from SBT with sbt run, it works fine. sbt compile works file too. How do I fix this so my project runs as an Application?
* Solution *
Manually add scala-reflect-2.11.8.jar
For me the following worked (without including scala-reflect to classpath):
Go to run configurations
Check the box Include dependencies with "Provided" scope
Please try running
sbt package
from the command line first. Then let us know if that fixes the issue.
Update Looked more closely. This is due to scala-reflect.jar not being picked up within intellij. You do have it the build.sbt:
"org.scala-lang" % "scala-reflect" % version % "provided",
Please add that dependency manually to the intellij project. Why IJ did not pick it up is uncertain so this is basically a hack. But with intellij fixes like this are unfortunately sometimes required.
If you are on a Mac, could you check if the issue is related to this : Class JavaLaunchHelper is implemented in both ... libinstrument.dylib. One of the two will be used. Which one is undefined
Also, I tried removing the Scala SDK from the Global libraries and added it again. Worked great !!
I solved this problem by adding scala-reflect.jar to Standard library.
This problem was ruining my day yesterday. Today I was prompted by intellij to download v2016.2 ( I was on v2016.1) and this problem went away. I have removed the following line from my build.sbt:
"org.scala-lang" % "scala-reflect" % version % "provided"
And was able to build and run the project successfully.
I think this is a duplicate of SBT, dependencies, classpath and editors. I solved it by adding this plugin from github

Play 2.0 unexpected exception StackOverflowError: null

When I try to compile my project I get the following exception:
! Internal server error, for request [GET /] ->
play.api.UnexpectedException: Unexpected exception [StackOverflowError: null]
at sbt.PlayReloader$$anon$2$$anonfun$reload$3$$anonfun$4$$anonfun$apply$12.apply(PlayReloader.scala:233) ~[na:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$3$$anonfun$4$$anonfun$apply$12.apply(PlayReloader.scala:226) ~[na:na]
at scala.Option.map(Option.scala:133) ~[scala-library.jar:0.11.3]
at sbt.PlayReloader$$anon$2$$anonfun$reload$3$$anonfun$4.apply(PlayReloader.scala:226) ~[na:na]
at sbt.PlayReloader$$anon$2$$anonfun$reload$3$$anonfun$4.apply(PlayReloader.scala:224) ~[na:na]
at scala.Either$LeftProjection.map(Either.scala:183) ~[scala-library.jar:0.11.3]
java.lang.StackOverflowError: null
at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:731) ~[scala-compiler.jar:na]
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4271) ~[scala-compiler.jar:na]
at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4138) ~[scala-compiler.jar:na]
at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:731) ~[scala-compiler.jar:na]
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4271) ~[scala-compiler.jar:na]
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$typedApply$1$1.apply(Typers.scala:3353) ~[scala-compiler.jar:na]
I found the same issue in the Play 2 issue tracker and they said that when the routes file grows it makes that exception.
Is there a solution to this exception because my project doesn't compile anymore ?
I'm using Play 2.0.3 for scala(my routes file is about 150 line)
I had the same issue with Play 2.0.6. Upgraded to Play 2.0.8 and it didn't help. I then modified the $play_dir/framework/build script so it builds with -Xss2M instead of -Xss1M and the problem disappeared (I can compile normally now).
There is a bug with play 2.0 having to do with the size of the routes file, not in terms of the number of routes but rather the physical size of the file (32768 bytes). It seems that this cieling has increased for 2.0.4 and is eliminated with 2.1.
https://groups.google.com/forum/?fromgroups=#!topic/play-framework/fZvgWJoCPLc
So, first, I would take a look at the physical size of the routes file. It may be possible cut out comments and/or eliminate commented-out lines. Next, I would try upgrading to version 2.0.4. That is a fairly easy process. You just need to download 2.0.4, point play to this new path, and update the /project/plugins.sbt of the project to read:
// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.0.4")
A more long-term fix may be to upgrade your project to 2.1 once it becomes stable.