Exception in thread "main" java.lang.NoClassDefFoundError: spray/json/BasicFormats$class
Closed this issue · 6 comments
Hi
i created a fresh intellij scala project to try diffson
this is the pom : it has diffson and spray dependences
<dependencies>
<dependency>
<groupId>io.spray</groupId>
<artifactId>spray-json_2.12</artifactId>
<version>1.3.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.gnieh/diffson -->
<dependency>
<groupId>org.gnieh</groupId>
<artifactId>diffson_2.11</artifactId>
<version>2.0.2</version>
</dependency>
</dependencies>
this is the code
import spray.json._
import gnieh.diffson.sprayJson._
object Differ extends App {
val json1 = """{
| "a": 1,
| "b": true,
| "c": "test"
|}""".stripMargin
val json2 = """{
| "a": 6,
| "c": "test2",
| "d": false
|}""".stripMargin
val patch = JsonDiff.diff(json1, json2, false)
println(patch)
}
i run, and this is the exception
Exception in thread "main" java.lang.NoClassDefFoundError: spray/json/BasicFormats$class
at gnieh.diffson.sprayJson.package$DiffsonProtocol$.<init>(package.scala:23)
at gnieh.diffson.sprayJson.package$DiffsonProtocol$.<clinit>(package.scala)
at gnieh.diffson.sprayJson.package$provider$.<init>(package.scala:186)
at gnieh.diffson.sprayJson.package$provider$.<clinit>(package.scala)
at gnieh.diffson.sprayJson.package$.provider(package.scala:160)
at gnieh.diffson.sprayJson.package$.provider(package.scala:21)
at gnieh.diffson.JsonDiffSupport$JsonDiff.diff(JsonDiff.scala:41)
at Differ$.delayedEndpoint$Differ$1(Differ.scala:18)
at Differ$delayedInit$body.apply(Differ.scala:4)
at scala.Function0.apply$mcV$sp(Function0.scala:34)
at scala.Function0.apply$mcV$sp$(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App.$anonfun$main$1$adapted(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:389)
at scala.App.main(App.scala:76)
at scala.App.main$(App.scala:74)
at Differ$.main(Differ.scala:4)
at Differ.main(Differ.scala)
Caused by: java.lang.ClassNotFoundException: spray.json.BasicFormats$class
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 18 more
this is the java version
C:\Users\andrea.bisello>java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
this is the scala version
C:\Users\andrea.bisello>scala -version
Scala code runner version 2.12.1 -- Copyright 2002-2016, LAMP/EPFL and Lightbend, Inc.
any suggestion?
thanks.
Hi,
You depend on diffson for scala 2.11 and spray-json for scala 2.12. There is no binary compatiblity between these scala versions. Your dependencies should match the scala version you are using, so you must upgrade your diffson dependency to diffson-spray-json_2.12
to have porper spray-json support.
Also, make sure to use the last diffson release (2.2.4)
Thanks.
i'm a newbie of Scala and i haven't understand the differences between the version in the artifactId and "version".
now this is my pom and it work.
<dependencies>
<!-- https://mvnrepository.com/artifact/io.spray/spray-json -->
<dependency>
<groupId>io.spray</groupId>
<artifactId>spray-json_2.12</artifactId>
<version>1.3.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.gnieh/diffson -->
<dependency>
<groupId>org.gnieh</groupId>
<artifactId>diffson-spray-json_2.12</artifactId>
<version>2.2.6</version>
</dependency>
</dependencies>
No problem. To understand this naming convention, maybe have a look at the sbt doc on cross-building. Unlike Java, Scala does not maintain binary compatibility between non-patch releases.
@satabin thanks again.
Another question :
why in maven https://mvnrepository.com/artifact/org.gnieh/diffson the last version i see is 2.0.2 but in the pom i can point to 2.2.6?
I split diffson in several modules starting with diffson 2.1.0 to support several JSON backends. The module you use is actually this one: https://mvnrepository.com/artifact/org.gnieh/diffson-spray-json.
The backend agnostic core feature is: https://mvnrepository.com/artifact/org.gnieh/diffson-core. You can depend on this one if you want to add a new JSON backend, not provided by default (e.g. Jackson).