SunBright SunBright - 1 month ago 20
Scala Question

Error : java.lang.NoClassDefFoundError: akka/util/Timeout



i would like create an API using spray.io, i'm follow every instruction from https://danielasfregola.com/2015/02/23/how-to-build-a-rest-api-with-spray/


after that, here's my code

package API.Configurations

import java.io.File

import com.typesafe.config.ConfigFactory
import akka.io.IO
import spray.can.Http
import akka.pattern.ask
import akka.util.Timeout
import scala.concurrent.duration._
import akka.actor.{ActorSystem, Props}

object MainServices
extends App
{
val configFile = new File("/home/ubuntu/conf/application.conf")

val getPortMYSQL = ConfigFactory.parseFile(configFile).getInt("port")
val getAddressMYSQL = ConfigFactory.parseFile(configFile).getString("address")
val getUsernameMYSQL = ConfigFactory.parseFile(configFile).getString("username")
val getPasswordMYSQL = ConfigFactory.parseFile(configFile).getString("password")

val getPortAPI = ConfigFactory.parseFile(configFile).getInt("port_api")
val getAddressAPI = ConfigFactory.parseFile(configFile).getString("address_api")

val getPortES = ConfigFactory.parseFile(configFile).getInt("port_es")
val getAddressES = ConfigFactory.parseFile(configFile).getString("address_es")
val getclusterNameES = ConfigFactory.parseFile(configFile).getString("clusterNameES")

implicit val system = ActorSystem("BRISK_API")
val service = system.actorOf(Props[ServicesControllers], "CONFIGURATION_BRISK_API")

import scala.concurrent.duration._
implicit val askTimeout = new Timeout(5.seconds)

// implicit val timeout = Timeout(5.seconds)
IO(Http) ? Http.Bind(service, interface = getAddressAPI, port = getPortAPI)

println(s"Detil Services MYSQL : Port = ${getPortMYSQL}, Address = ${getAddressMYSQL}, Username = ${getUsernameMYSQL}, Password = ${getPasswordMYSQL}")
println(s"Detil Services API : Port = ${getPortAPI}, Address = ${getAddressAPI}")
println(s"Detil Services ES : Port = ${getPortES}, Address = ${getAddressES}, ClusterName = ${getclusterNameES}")
}


when im trying to use script : sbt run, im getting error. the compiler said :

[error] (run-main-0) java.lang.NoClassDefFoundError: akka/util/Timeout
java.lang.NoClassDefFoundError: akka/util/Timeout
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
Caused by: java.lang.ClassNotFoundException: akka.util.Timeout
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
[trace] Stack trace suppressed: run last compile:run for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code: 1
[error] Total time: 0 s, completed Oct 14, 2016 5:33:23 PM


always at akka/util/timeout, any idea how to handle this?
thanks.

EDIT 1 :
i was followed from those link, but the result is still the same as before.
Play 2.5 with Akka - could not find implicit value for parameter timeout: akka.util.Timeout

EDIT 2 :
my build.sbt

name := "SBTSR2016"

version := "1.0"
mainClass in Compile := Some("API.Configurations.MainServices")

scalaVersion := "2.10.5"

assemblyMergeStrategy in assembly := {
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case x => MergeStrategy.first
}

resolvers += "spray repo" at "http://repo.spray.io"
resolvers += "spray nightlies repo" at "http://nightlies.spray.io"

libraryDependencies += "io.spray" % "spray-json_2.10" % "1.3.2" % "provided"
libraryDependencies += "io.spray" % "spray-can_2.10" % "1.3.2" % "provided"
libraryDependencies += "io.spray" % "spray-client_2.10" % "1.3.2" % "provided"
libraryDependencies += "io.spray" % "spray-testkit_2.10" % "1.3.2" % "provided"
//libraryDependencies += "io.spray" % "spray-routing_2.10" % "1.3.2" % "provided"
libraryDependencies += "io.spray" % "spray-http_2.10" % "1.3.2" % "provided"
libraryDependencies += "io.spray" % "spray-httpx_2.10" % "1.3.2" % "provided"
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.12" % "provided"
libraryDependencies += "org.elasticsearch" % "elasticsearch" % "2.3.1" % "provided"
libraryDependencies += "com.sksamuel.elastic4s" % "elastic4s-streams_2.10" % "2.3.1" % "provided"
//libraryDependencies += "org.elasticsearch" % "elasticsearch" % "1.3.2"
libraryDependencies += "org.elasticsearch" % "elasticsearch-mapper-attachments" % "2.3.1" % "provided"
libraryDependencies += "com.typesafe" % "config" % "1.2.1" % "provided"
libraryDependencies += "io.spray" % "spray-routing-shapeless2_2.10" % "1.3.2"
//libraryDependencies += "com.typesafe.akka" % "akka-actor_2.10" % "2.3.4" % "provided"
libraryDependencies += "com.typesafe.akka" % "akka-actor_2.10" % "2.3.1" % "provided"

Answer

at build.sbt, add some code, below this :

mergeStrategy in assembly := {
 case m if m.toLowerCase.endsWith("manifest.mf") => MergeStrategy.discard
 case m if m.toLowerCase.matches("meta-inf.*\\.sf$") => MergeStrategy.discard
 case "reference.conf" => MergeStrategy.concat
 case _ => MergeStrategy.first
}

and it's works for me.
reference link : https://blog.knoldus.com/2015/07/20/spark-with-spray-starter-kit/comment-page-1/