Unknown Error from SBT console for dispatch-Http Get request - scala

I m doing simple Http GET request by using dispatch library in SBT.
My Code:
def getReq(){
val svc = url(GlobalObjects.BASE_GET_REQUEST_URL);
val response : Future[String] = Http(svc OK as.String)
response onComplete {
case Success(content) => {
println("Successful response" + content)
}
case Failure(t) => {
println("An error has occurred: " + t.getMessage)
}
}
}
}
When I run from SBT console it shows the following unKnown Error. Someone has any idea what is wrong here?
[error] (run-main) java.lang.NoSuchMethodError: scala.runtime.ObjectRef.zero()Ls
cala/runtime/ObjectRef;
java.lang.NoSuchMethodError: scala.runtime.ObjectRef.zero()Lscala/runtime/Object
Ref;
at dispatch.InternalDefaults$SbtProcessDefaults$.builder(defaults.scala)
at dispatch.InternalDefaults$.client(defaults.scala:32)
at dispatch.Http$.<init>(execution.scala:30)
at dispatch.Http$.<clinit>(execution.scala)
at com.czechscala.blank.User.getReq(User.scala:30)
at com.czechscala.blank.Hello$.main(Hello.scala:81)
at com.czechscala.blank.Hello.main(Hello.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
[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: 4 s, completed May 24, 2015 9:00:58 PM
In case I am posting my build.sbt as well.
my build.sbt:
name := "blank"
version := "1.0-SNAPSHOT"
scalaVersion := "2.10.2"
libraryDependencies ++= Seq (
"org.scalatest" % "scalatest_2.10" % "1.9.1" % "test"
)
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.1.2"
)
libraryDependencies ++= Seq(
"net.databinder" %% "dispatch" % "0.8.10"
)
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-actors" % "2.10.2"
)
libraryDependencies ++= Seq(
"net.databinder" %% "dispatch-core" % "0.8.10"
)
libraryDependencies ++= Seq(
"net.databinder" %% "dispatch-futures" % "0.8.10"
)
libraryDependencies ++= Seq(
"net.databinder" %% "dispatch-nio" % "0.8.10"
)
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % "1.6.4",
"org.slf4j" % "slf4j-simple" % "1.6.4"
)
libraryDependencies ++= Seq(
"org.json4s" %% "json4s-core" % "3.2.10",
"org.json4s" %% "json4s-native" % "3.2.10",
"org.json4s" %% "json4s-jackson" % "3.2.10",
"net.databinder" %% "unfiltered-netty" % "0.8.0" % "test",
"net.databinder.dispatch" % "dispatch-json4s-native_2.11" % "0.11.1"
)
libraryDependencies ++= Seq(
"io.argonaut" %% "argonaut" % "6.0.4"
)
initialCommands := "import dispatch._"

Seems to be the same issue as with your other question.
net.databinder.dispatch is using 2.11 instead 2.10.

Related

Abstract Method Error In GraphLoader Object

I have created a simple project in Graphx, as soon as I am trying to run this test project, I am getting AbstractMethodError, error is comming inside this method edgeListFile, looks like something related to logger which I am not abe to see, Please help.
Here is my .scala file
object graphtest extends App {
import org.apache.spark.graphx.{GraphLoader, VertexId}
val spark = SparkSession.builder.master("local").appName("learning spark").getOrCreate
val sc = spark.sparkContext
val graph1 = GraphLoader.edgeListFile(spark.sparkContext, "E:\\code\\Cit-HepTh.txt")
val res: (VertexId, Int) = graph1.inDegrees.reduce((a, b) => if (a._2 > b._2) a else b)
graph1.edges.collect().take(10).foreach(println)
}
Here is my build.sbt file
name := "myproject"
version := "0.1"
scalaVersion := "2.11.8"
mainClass in (Compile, packageBin) := Some("myproject.Processor")
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % "2.3.1",
"org.apache.spark" %% "spark-sql" % "2.3.1",
"org.scalatest" %% "scalatest" % "3.2.0-SNAP10" % Test,
"com.typesafe" % "config" % "1.3.1",
"org.apache.spark" %% "spark-mllib" % "2.0.1"
)
and finally the complete failed stacktrace
Exception in thread "main" java.lang.AbstractMethodError
at org.apache.spark.internal.Logging$class.initializeLogIfNecessary(Logging.scala:99)
at org.apache.spark.graphx.GraphLoader$.initializeLogIfNecessary(GraphLoader.scala:28)
at org.apache.spark.internal.Logging$class.log(Logging.scala:46)
at org.apache.spark.graphx.GraphLoader$.log(GraphLoader.scala:28)
at org.apache.spark.internal.Logging$class.logInfo(Logging.scala:54)
at org.apache.spark.graphx.GraphLoader$.logInfo(GraphLoader.scala:28)
at org.apache.spark.graphx.GraphLoader$.edgeListFile(GraphLoader.scala:96)
at aaa.graphtest$.delayedEndpoint$zettasense$graphtest$1(Test.scala:15)
at aaa.graphtest$delayedInit$body.apply(Test.scala:6)
at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:381)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.App$class.main(App.scala:76)
at aaa.graphtest$.main(Test.scala:6)
at aaa.graphtest.main(Test.scala)
It was a library mismatch, I updated spark-core, spark-sql, spark-mlib to the latest version and it worked smoothly, here is how my build.sbt looks now
name := "myproject"
version := "0.1"
scalaVersion := "2.11.8"
mainClass in(Compile, packageBin) := Some("myproject.Processor")
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % "2.4.0",
"org.apache.spark" %% "spark-sql" % "2.4.0",
"org.scalatest" %% "scalatest" % "3.2.0-SNAP10" % Test,
"com.typesafe" % "config" % "1.3.1",
"org.apache.spark" %% "spark-mllib" % "2.4.0"
)

play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: slick/backend/DatabaseConfig]

I'm tring to setup a project with play framework and postgres with slick-codegen. My project is compiling without errors And the Tables class generated is correct. But when I run the project it give me the play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: slick/backend/DatabaseConfig].
This is the full trace:
play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: slick/backend/DatabaseConfig]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:184)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:131)
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:131)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:129)
at scala.util.Success.flatMap(Try.scala:231)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:129)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:121)
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.NoClassDefFoundError: slick/backend/DatabaseConfig
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:688)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:380)
at com.google.inject.internal.ConstructorBindingImpl.getInternalDependencies(ConstructorBindingImpl.java:165)
at com.google.inject.internal.InjectorImpl.getInternalDependencies(InjectorImpl.java:616)
at com.google.inject.internal.InjectorImpl.cleanup(InjectorImpl.java:572)
at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:558)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:887)
Caused by: java.lang.ClassNotFoundException: slick.backend.DatabaseConfig
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.getDeclaredMethods(Class.java:1975)
at com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:688)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:380)
at com.google.inject.internal.ConstructorBindingImpl.getInternalDependencies(ConstructorBindingImpl.java:165)
at com.google.inject.internal.InjectorImpl.getInternalDependencies(InjectorImpl.java:616)
I have my project split in 2 subprojects. The Play project and the codegen project that is used to generate the Tables class.
My build.sbt looks like this:
import sbt.Keys._
val slickVersion = "3.2.0"
scalaVersion := "2.11.8"
// The Play project itself
lazy val root = (project in file("."))
.settings(
libraryDependencies ++= List(
"com.netaporter" %% "scala-uri" % "0.4.14",
"net.codingwell" %% "scala-guice" % "4.1.0",
"com.typesafe.play" %% "play-slick" % "2.0.2",
"com.typesafe.play" %% "play-slick-evolutions" % "2.0.2"
)
)
.settings(sharedSettings)
.enablePlugins(Common, PlayScala)
.settings(
name := """Play app"""
)
.dependsOn(codegen)
lazy val codegen = project
.settings(sharedSettings)
.settings(
libraryDependencies ++= List(
"com.typesafe.slick" %% "slick-codegen" % slickVersion
)
)
lazy val sharedSettings = Seq(
scalaVersion := "2.11.8",
scalacOptions := Seq("-feature", "-unchecked", "-deprecation"),
libraryDependencies ++= List(
"com.typesafe.scala-logging" %% "scala-logging-slf4j" % "2.1.2",
"org.slf4j" % "slf4j-api" % "1.7.23",
"org.slf4j" % "log4j-over-slf4j" % "1.7.23", // for any java classes looking for this
"ch.qos.logback" % "logback-classic" % "1.2.1",
"com.typesafe.slick" %% "slick" % slickVersion,
"org.postgresql" % "postgresql" % "9.4.1212",
"com.github.tminglei" %% "slick-pg" % "0.15.0-RC",
"com.github.tminglei" %% "slick-pg_play-json" % "0.15.0-RC",
"com.github.tminglei" %% "slick-pg_joda-time" % "0.15.0-RC",
"com.github.tminglei" %% "slick-pg_jts" % "0.15.0-RC",
"joda-time" % "joda-time" % "2.9.7",
"org.joda" % "joda-convert" % "1.8"
)
)
I also tried removing all the code that use database and the Tables class but i still get this error.
I use a custom postgres driver and it is in the codegen project but is i add the dependsOn(codegen) in the root project, it should not be a problem. Also it is compling without problems with sbt compile.
EDIT:
After some testings, i changed the slick version to 3.1.1 and com.github.tminglei versions to 0.14.3 and it now works for me.
I had the same classapth problem and in the end used the following versions in a play-2.5.x and scala-2.11 project:
libraryDependencies ++= List(
"com.typesafe.play" %% "play-slick" % "2.1.0",
"com.typesafe.play" %% "play-slick-evolutions" % "2.1.0",
"com.typesafe.slick" %% "slick" % "3.2.0",
"com.github.tototoshi" %% "slick-joda-mapper" % "2.3.0"
}
The slick.backend.DatabaseConfig comes from slick-3.1.0 that was needed by play-slick-2.0.2. Since you wanted slick-3.2.0 you need to use play-slick-2.1.0 see https://github.com/playframework/play-slick and https://github.com/tototoshi/slick-joda-mapper .

sbt assembly error deduplicate

Getting started with sbt.
I am getting this error during sbt assembly
deduplicate: different file contents found in the following:
../.ivy2/cache/org.scalatest/scalatest_2.11/bundles/scalatest_2.11-2.2.6.jar:org/scalactic/SeqEqualityConstraints$.class
../.ivy2/cache/org.scalactic/scalactic_2.11/bundles/scalactic_2.11-3.0.0.jar:org/scalactic/SeqEqualityConstraints$.class
this is my build sbt :
scalaVersion := "2.11.8"
scalacOptions := Seq("-unchecked", "-feature", "-deprecation", "-encoding", "utf8")
libraryDependencies ++= {
val phantomV = "1.29.5"
val scalaTestV = "2.2.6"
val scalaMockV = "3.4.2"
val elastic4sV = "2.4.0"
val akkaStreamVersion = "2.4.10"
val akkaVersion = "2.3.12"
Seq(
"com.websudos" %% "phantom-dsl" % phantomV,
"com.websudos" %% "phantom-reactivestreams" % phantomV,
"com.websudos" %% "util-testing" % "0.13.0" % "test, provided",
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
"com.typesafe.akka" %% "akka-http-spray-json-experimental" % akkaStreamVersion,
"com.typesafe.akka" %% "akka-http-core" % akkaStreamVersion,
"com.typesafe.akka" %% "akka-http-experimental" % akkaStreamVersion,
"com.typesafe.akka" %% "akka-http-testkit" % akkaStreamVersion,
"com.typesafe.akka" %% "akka-stream" % akkaStreamVersion,
"com.typesafe.akka" %% "akka-stream-testkit" % akkaStreamVersion,
"org.scalatest" %% "scalatest" % scalaTestV % "test, provided",
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % "test, provided",
"com.typesafe.play" %% "play-streams-experimental" % "2.4.6" % "provided",
"com.sksamuel.elastic4s" %% "elastic4s-core" % elastic4sV,
"com.sksamuel.elastic4s" %% "elastic4s-streams" % elastic4sV,
"org.scalamock" %% "scalamock-scalatest-support" % scalaMockV % "test, provided",
"com.typesafe" % "config" % "1.3.1"
)
}
lazy val root = project.in(file("."))
.settings(mainClass in assembly := Some("com.ind.Main"))
initialCommands := """|import akka.actor._
|import akka.pattern._
|import akka.util._
|import scala.concurrent._
|import scala.concurrent.duration._""".stripMargin
fork in run := true
test in assembly := {}
any idea why am getting that and how can I solve it ?
===== UPDATE ====
I did managed to solve it by adding
assemblyMergeStrategy in assembly := {
case PathList("META-INF", xs # _*) => MergeStrategy.discard
case x => MergeStrategy.first
}
assemblyMergeStrategy in assembly := {
case PathList("META-INF", xs # _*) => MergeStrategy.discard
case x => MergeStrategy.first
}
The ScalaTest and Scalactic version numbers need to match. You have a ScalaTest 2.2.6 trying to use a Scalactic 3.0.0, so that's the problem. One of your dependencies is perhaps using Scalactic 3.0.0.

Spray microservice assembly deduplicate

I'm using this template to develop a microservice:
http://www.typesafe.com/activator/template/activator-service-container-tutorial
My sbt file is like this:
import sbt._
import Keys._
name := "activator-service-container-tutorial"
version := "1.0.1"
scalaVersion := "2.11.6"
crossScalaVersions := Seq("2.10.5", "2.11.6")
resolvers += "Scalaz Bintray Repo" at "https://dl.bintray.com/scalaz/releases"
libraryDependencies ++= {
val containerVersion = "1.0.1"
val configVersion = "1.2.1"
val akkaVersion = "2.3.9"
val liftVersion = "2.6.2"
val sprayVersion = "1.3.3"
Seq(
"com.github.vonnagy" %% "service-container" % containerVersion,
"com.github.vonnagy" %% "service-container-metrics-reporting" % containerVersion,
"com.typesafe" % "config" % configVersion,
"com.typesafe.akka" %% "akka-actor" % akkaVersion exclude ("org.scala-lang" , "scala-library"),
"com.typesafe.akka" %% "akka-slf4j" % akkaVersion exclude ("org.slf4j", "slf4j-api") exclude ("org.scala-lang" , "scala-library"),
"ch.qos.logback" % "logback-classic" % "1.1.3",
"io.spray" %% "spray-can" % sprayVersion,
"io.spray" %% "spray-routing" % sprayVersion,
"net.liftweb" %% "lift-json" % liftVersion,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % "test",
"io.spray" %% "spray-testkit" % sprayVersion % "test",
"junit" % "junit" % "4.12" % "test",
"org.scalaz.stream" %% "scalaz-stream" % "0.7a" % "test",
"org.specs2" %% "specs2-core" % "3.5" % "test",
"org.specs2" %% "specs2-mock" % "3.5" % "test",
"com.twitter" %% "finagle-http" % "6.25.0",
"com.twitter" %% "bijection-util" % "0.7.2"
)
}
scalacOptions ++= Seq(
"-unchecked",
"-deprecation",
"-Xlint",
"-Ywarn-dead-code",
"-language:_",
"-target:jvm-1.7",
"-encoding", "UTF-8"
)
crossPaths := false
parallelExecution in Test := false
assemblyJarName in assembly := "santo.jar"
mainClass in assembly := Some("Service")
The project compiles fine!
But when I run assembly, the terminal show me this:
[error] (*:assembly) deduplicate: different file contents found in the following:
[error] /path/.ivy2/cache/io.dropwizard.metrics/metrics-core/bundles/metrics-core-3.1.1.jar:com/codahale/metrics/ConsoleReporter$1.class
[error] /path/.ivy2/cache/com.codahale.metrics/metrics-core/bundles/metrics-core-3.0.1.jar:com/codahale/metrics/ConsoleReporter$1.class
What options do I have to fix it?
Thanks
The issue as it seems transitive dependency of the dependency is resulting with two different versions of metrics-core. The best thing to do would be to used the right library dependency so that you end up with a single version of this library. Please use https://github.com/jrudolph/sbt-dependency-graph , if it is difficult to figure out dependencies.
If it is not possible to get to a single version then you would most likely to go down exclude route . I assume, this only work, if there is compatibility between the all required versions.

Unexpected exception in Play with Scala

I am having an Unexpected exception in my Play2 application with Scala. The same error as mentioned in this question
This is what I get in a browser:
scala.MatchError: java.lang.StackOverflowError (of class
java.lang.StackOverflowError)
play.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44)
play.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44)
scala.Option.map(Option.scala:145)
play.PlayReload$.taskFailureHandler(PlayReload.scala:44)
play.PlayReload$.compileFailure(PlayReload.scala:40)
play.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)
play.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)
scala.util.Either$LeftProjection.map(Either.scala:377)
play.PlayReload$.compile(PlayReload.scala:17)
My stack traces are very large. A part of them looks as follows:
scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5332)
at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5279)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5283)
at
scala.tools.nsc.typechecker.Typers$Typer$$anonfun$93.apply(Typers.scala:4440)
[error] (compile:compile) java.lang.StackOverflowError [error]
application -
! Internal server error, for (GET) [/] ->
scala.MatchError: java.lang.StackOverflowError (of class
java.lang.StackOverflowError) at
play.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44)
~[na:na] at
play.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44)
~[na:na] at scala.Option.map(Option.scala:145)
~[scala-library-2.11.5.jar:na] at
play.PlayReload$.taskFailureHandler(PlayReload.scala:44) ~[na:na] at
play.PlayReload$.compileFailure(PlayReload.scala:40) ~[na:na]
I have tried the answers to change the heap and stack size but when I run jconsole it showed that it did not work.
I also tried to change its heap size from this link but it also did not work and I am still getting the same error.
Here is my build.sbt file :
name := """myproject"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.1"
fork in run := true
javaOptions in run ++= Seq(
"-Xms1G", "-Xmx2G", "-XX:MaxPermSize=1024M", "-XX:+UseConcMarkSweepGC")
//SBT_OPTS=-Xss8m
//JAVA_OPTS="-Xms512m "
//val buildSettings = Defaults.defaultSettings ++ Seq( javaOptions += "-Xms1G -Xmx2G"
//)
libraryDependencies ++= Seq("org.scalatest" %% "scalatest" % "2.2.1" % "test"withSources() withJavadoc(),
"com.esotericsoftware.kryo" % "kryo" % "2.10",
"org.mongodb" %% "casbah" % "2.8.0",
"org.slf4j" % "slf4j-api" % "1.6.4",
"org.elasticsearch" % "elasticsearch" % "1.5.0",
"org.scalatest" %% "scalatest" % "2.2.1" % "test"withSources() withJavadoc(),
"org.easymock" % "easymock" % "3.1" withSources() withJavadoc(),
"org.mockito" % "mockito-all" % "1.9.5",
"com.typesafe.akka" %% "akka-actor" % "2.3.6",
"ch.qos.logback" % "logback-core" % "1.0.9",
"ch.qos.logback" % "logback-classic" % "1.0.9"
)
Please guide me.
Changing the stack size worked for me
I used this command to run the project
activator run -J-Xss4M -server