1

I am attempting to use the Eclipse Scala-IDE for 2.11 (downloaded the prepackaged bundle from the web-site). I have been using the Scala Worksheet to work with a SaaS API returning JSON. I've been pushing through just using String methods. I decided to begin using json4s. I went to http://mvnrepository.com/ and obtained the following libraries:

  • json4s-core-2.11-3.2.10.jar
  • json4s-native-2.11-3.2.10.jar
  • paranamer-2.6.jar

I have added all three jars to the Project's Build Path. And they appear under the project's "Referenced Libraries".

I have the following code in a Scala Worksheet:

package org.public_domain

import org.json4s._
import org.json4s.native.JsonMethods._

object WorkSheet6 {
  println("Welcome to the Scala worksheet")
  parse(""" { "numbers" : [1, 2, 3, 4] } """)
  println("Bye")
}

I am receiving the following two compilation errors:

  • bad symbolic reference to org.json4s.JsonAST.JValue encountered in class file 'package.class'. Cannot access type JValue in value org.json4s.JsonAST. The current classpath may be missing a definition for org.json4s.JsonAST.JValue, or package.class may have been compiled against a version that's incompatible with the one found on the current classpath.
  • bad symbolic reference to org.json4s.JsonAST.JValue encountered in class file 'package.class'. Cannot access type JValue in value org.json4s.JsonAST. The current classpath may be missing a definition for org.json4s.JsonAST.JValue, or package.class may have been compiled against a version that's incompatible with the one found on the current classpath.

When I go look in the org.json4s package in the json4s-core-2.11-3.2.10.jar file, there is in fact no .class file indicating any sort of compiled object JsonAST.

This is a showstopper. Any help on this would be greatly appreciated.

chaotic3quilibrium
  • 5,661
  • 8
  • 53
  • 86

1 Answers1

5

Your classpath is incomplete. You are missing a dependency of json4s-core.

bad symbolic reference to org.json4s.JsonAST.JValue encountered in class file 'package.class'. Cannot access type JValue in value org.json4s.JsonAST. The current classpath may be missing a definition for org.json4s.JsonAST.JValue, or package.class may have been compiled against a version that's incompatible with the one found on the current classpath.

The simplest way to consume Scala or Java libraries is to use sbt or maven. They bring in (transitive) dependencies for you. If you check the pom definition of json4s-core library, you notice it depends on json4s-ast. You should add that jar to your build path as well.

Iulian Dragos
  • 5,692
  • 23
  • 31
  • Is sbt included with the Eclipse Scala-IDE (3.0.4)? If so, how do I go about setting it up for my project? When I selected New/Scala Project from the file Menu, it didn't ask me or include anything about sbt. – chaotic3quilibrium Jul 22 '14 at 11:45
  • 1
    No, Sbt is not part of Scala IDE. It is a command-line build tool, like maven or gradle. http://www.scala-sbt.org/0.13/tutorial/index.html – Iulian Dragos Jul 23 '14 at 14:09