I'm new to spray, i can't get it to work... :/
My build.sbt:
val apacheDeps = Seq(
"commons-validator" % "commons-validator" % "1.4.1"
)
val sprayAndAkkaDeps = {
val sprayV = "1.3.3"
Seq(
"io.spray" %% "spray-can" % sprayV,
"io.spray" %% "spray-routing" % sprayV,
"io.spray" %% "spray-testkit" % sprayV % "test",
"com.typesafe.akka" %% "akka-actor" % "2.3.9"
)
}
name := "myApp"
version := "1.0.0"
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
"org.mongodb" %% "casbah" % "2.8.1",
"ch.qos.logback" % "logback-classic" % "1.1.2",
"org.scala-lang.modules" %% "scala-xml" % "1.0.3",
"com.typesafe.play" %% "play-json" % "2.4.0",
"org.specs2" %% "specs2-core" % "3.6.1" % "test",
"com.netaporter" %% "scala-uri" % "0.4.7"
) ++ apacheDeps ++ sprayAndAkkaDeps
Revolver.settings
My main object:
import akka.actor._
import akka.io.IO
import akka.pattern.ask
import spray.can.Http
import akka.util.Timeout
import scala.concurrent.duration._
object Main extends App {
implicit val timeout = new Timeout(5.seconds)
implicit val system = ActorSystem("acontextGen")
val listener = system.actorOf(Props[listeners.MyHttpListener], "httpListener")
IO(Http) ? Http.Bind(listener, interface = "localhost", port = 7777)
}
My listener:
package listeners
import spray.routing._
class MyHttpListener extends HttpServiceActor {
def receive = runRoute {
path("hi") {
get {
complete("hello")
}
}
}
}
And the problem. When i run i get this output and server doesn't start on 7777 port
> gen[ERROR] Uncaught error from thread [acontextGen-akka.actor.default-dispatcher-2] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[acontextGen]
gen[ERROR] java.lang.NoClassDefFoundError: shapeless/PrependAux$
gen[ERROR] at spray.routing.directives.PathDirectives$class.pathPrefix(PathDirectives.scala:40)
gen[ERROR] at spray.routing.HttpServiceActor.pathPrefix(HttpService.scala:96)
gen[ERROR] at spray.routing.directives.PathDirectives$class.path(PathDirectives.scala:33)
gen[ERROR] at spray.routing.HttpServiceActor.path(HttpService.scala:96)
gen[ERROR] at listeners.MyHttpListener.receive(MyHttpListener.scala:9)
gen[ERROR] at akka.actor.ActorCell.newActor(ActorCell.scala:558)
gen[ERROR] at akka.actor.ActorCell.create(ActorCell.scala:578)
gen[ERROR] at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:456)
gen[ERROR] at akka.actor.ActorCell.systemInvoke(ActorCell.scala:478)
gen[ERROR] at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:279)
gen [ERROR] [06/19/2015 18:41:00.089] [acontextGen-akka.actor.default-dispatcher-2] [ActorSystem(acontextGen)] Uncaught error from thread [acontextGen-akka.actor.default-dispatcher-2] shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled
gen java.lang.NoClassDefFoundError: shapeless/PrependAux$
gen at spray.routing.directives.PathDirectives$class.pathPrefix(PathDirectives.scala:40)
gen at spray.routing.HttpServiceActor.pathPrefix(HttpService.scala:96)
gen at spray.routing.directives.PathDirectives$class.path(PathDirectives.scala:33)
gen at spray.routing.HttpServiceActor.path(HttpService.scala:96)
gen at listeners.MyHttpListener.receive(MyHttpListener.scala:9)
gen at akka.actor.ActorCell.newActor(ActorCell.scala:558)
gen at akka.actor.ActorCell.create(ActorCell.scala:578)
gen at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:456)
gen at akka.actor.ActorCell.systemInvoke(ActorCell.scala:478)
gen at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:279)
gen at akka.dispatch.Mailbox.run(Mailbox.scala:220)
gen at akka.dispatch.Mailbox.exec(Mailbox.scala:231)
gen at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
gen at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.pollAndExecAll(ForkJoinPool.java:1253)
gen at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1346)
gen at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
gen at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
gen Caused by: java.lang.ClassNotFoundException: shapeless.PrependAux$
gen at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
gen at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
gen at java.security.AccessController.doPrivileged(Native Method)
gen at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
gen at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
gen at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
gen ... 17 more
gen
gen[ERROR] at akka.dispatch.Mailbox.run(Mailbox.scala:220)
gen[ERROR] at akka.dispatch.Mailbox.exec(Mailbox.scala:231)
gen[ERROR] at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
gen[ERROR] at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.pollAndExecAll(ForkJoinPool.java:1253)
gen[ERROR] at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1346)
gen[ERROR] at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
gen[ERROR] at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
gen[ERROR] Caused by: java.lang.ClassNotFoundException: shapeless.PrependAux$
gen[ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
gen[ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
gen[ERROR] at java.security.AccessController.doPrivileged(Native Method)
gen[ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
gen[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
gen[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
gen[ERROR] ... 17 more
gen ... finished with exit code 255
Could you explain me what am i doing wrong? I have followed this example: https://github.com/spray/spray-template/tree/on_spray-can_1.3 which works although
> show externalDependencyClasspath
[info] List(Attributed(/home/user256/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.6.jar), Attributed(/home/user256/.ivy2/cache/org.mongodb/casbah-commons_2.11/jars/casbah-commons_2.11-2.8.1.jar), Attributed(/home/user256/.ivy2/cache/com.github.nscala-time/nscala-time_2.11/jars/nscala-time_2.11-1.0.0.jar), Attributed(/home/user256/.ivy2/cache/org.mongodb/mongo-java-driver/jars/mongo-java-driver-2.13.1.jar), Attributed(/home/user256/.ivy2/cache/org.mongodb/casbah-core_2.11/jars/casbah-core_2.11-2.8.1.jar), Attributed(/home/user256/.ivy2/cache/org.mongodb/casbah-query_2.11/jars/casbah-query_2.11-2.8.1.jar), Attributed(/home/user256/.ivy2/cache/org.mongodb/casbah-gridfs_2.11/jars/casbah-gridfs_2.11-2.8.1.jar), Attributed(/home/user256/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.1.2.jar), Attributed(/home/user256/.ivy2/cache/ch.qos.logback/logback-core/jars/logback-core-1.1.2.jar), Attributed(/home/user256/.ivy2/cache/org.slf4j/slf4j-api/jars/slf4j-api-1.7.6.jar), Attributed(/home/user256/.ivy2/cache/org.scala-lang.modules/scala-xml_2.11/bundles/scala-xml_2.11-1.0.3.jar), Attributed(/home/user256/.ivy2/cache/com.typesafe.play/play-json_2.11/jars/play-json_2.11-2.4.0.jar), Attributed(/home/user256/.ivy2/cache/com.typesafe.play/play-iteratees_2.11/jars/play-iteratees_2.11-2.4.0.jar), Attributed(/home/user256/.ivy2/cache/org.scala-stm/scala-stm_2.11/jars/scala-stm_2.11-0.7.jar), Attributed(/home/user256/.ivy2/cache/com.typesafe/config/bundles/config-1.3.0.jar), Attributed(/home/user256/.ivy2/cache/com.typesafe.play/play-functional_2.11/jars/play-functional_2.11-2.4.0.jar), Attributed(/home/user256/.ivy2/cache/com.typesafe.play/play-datacommons_2.11/jars/play-datacommons_2.11-2.4.0.jar), Attributed(/home/user256/.ivy2/cache/joda-time/joda-time/jars/joda-time-2.7.jar), Attributed(/home/user256/.ivy2/cache/org.joda/joda-convert/jars/joda-convert-1.7.jar), Attributed(/home/user256/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.11.6.jar), Attributed(/home/user256/.ivy2/cache/com.fasterxml.jackson.core/jackson-core/bundles/jackson-core-2.5.3.jar), Attributed(/home/user256/.ivy2/cache/com.fasterxml.jackson.core/jackson-annotations/bundles/jackson-annotations-2.5.3.jar), Attributed(/home/user256/.ivy2/cache/com.fasterxml.jackson.core/jackson-databind/bundles/jackson-databind-2.5.3.jar), Attributed(/home/user256/.ivy2/cache/com.fasterxml.jackson.datatype/jackson-datatype-jdk8/bundles/jackson-datatype-jdk8-2.5.3.jar), Attributed(/home/user256/.ivy2/cache/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/bundles/jackson-datatype-jsr310-2.5.3.jar), Attributed(/home/user256/.ivy2/cache/com.netaporter/scala-uri_2.11/jars/scala-uri_2.11-0.4.7.jar), Attributed(/home/user256/.ivy2/cache/org.parboiled/parboiled_2.11/jars/parboiled_2.11-2.0.1.jar), Attributed(/home/user256/.ivy2/cache/commons-validator/commons-validator/jars/commons-validator-1.4.1.jar), Attributed(/home/user256/.ivy2/cache/commons-beanutils/commons-beanutils/jars/commons-beanutils-1.8.3.jar), Attributed(/home/user256/.ivy2/cache/commons-logging/commons-logging/jars/commons-logging-1.2.jar), Attributed(/home/user256/.ivy2/cache/commons-digester/commons-digester/jars/commons-digester-1.8.1.jar), Attributed(/home/user256/.ivy2/cache/commons-collections/commons-collections/jars/commons-collections-3.2.1.jar), Attributed(/home/user256/.ivy2/cache/io.spray/spray-can_2.11/bundles/spray-can_2.11-1.3.3.jar), Attributed(/home/user256/.ivy2/cache/io.spray/spray-io_2.11/bundles/spray-io_2.11-1.3.3.jar), Attributed(/home/user256/.ivy2/cache/io.spray/spray-util_2.11/bundles/spray-util_2.11-1.3.3.jar), Attributed(/home/user256/.ivy2/cache/io.spray/spray-http_2.11/bundles/spray-http_2.11-1.3.3.jar), Attributed(/home/user256/.ivy2/cache/org.parboiled/parboiled-scala_2.11/jars/parboiled-scala_2.11-1.1.7.jar), Attributed(/home/user256/.ivy2/cache/org.parboiled/parboiled-core/jars/parboiled-core-1.1.7.jar), Attributed(/home/user256/.ivy2/cache/io.spray/spray-routing-shapeless2_2.11/bundles/spray-routing-shapeless2_2.11-1.3.3.jar), Attributed(/home/user256/.ivy2/cache/io.spray/spray-httpx_2.11/bundles/spray-httpx_2.11-1.3.3.jar), Attributed(/home/user256/.ivy2/cache/org.jvnet.mimepull/mimepull/jars/mimepull-1.9.5.jar), Attributed(/home/user256/.ivy2/cache/com.chuusai/shapeless_2.11/bundles/shapeless_2.11-2.1.0.jar), Attributed(/home/user256/.ivy2/cache/com.typesafe.akka/akka-actor_2.11/jars/akka-actor_2.11-2.3.9.jar))
The reason is that shapeless 1.x and shapeless 2.x are not compatible. However, if you mix dependencies that depend on both versions of shapeless sbt's dependency manager will by default just evict the older version. That's what happened here:
> dependencyTree
myapp:myapp_2.11:1.0.0 [S]
+-com.netaporter:scala-uri_2.11:0.4.7 [S]
| +-org.parboiled:parboiled_2.11:2.0.1 [S]
| +-com.chuusai:shapeless_2.11:2.0.0 [S]
|
+-io.spray:spray-routing_2.11:1.3.3 [S]
| +-com.chuusai:shapeless_2.11:1.2.4 (evicted by: 2.0.0)
| +-io.spray:spray-http_2.11:1.3.3 [S]
| | +-io.spray:spray-util_2.11:1.3.3 [S]
| | +-org.parboiled:parboiled-scala_2.11:1.1.7 [S]
| | +-org.parboiled:parboiled-core:1.1.7
| | ...
spray-routing
still depends on shapeless
1.x while scala-uri
relies on parboiled2
which depends on shapeless
2.x.
The solution is to use the spray-routing-shapeless2
module which was built specifically to help with problems like this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With