有下面的scala代码
package jobs import org.json4s._ import org.json4s.jackson.JsonMethods._ object Test { def main(args: Array[String]): Unit = { case class Person(name: String, age: Int, city: String) // Parse JSON string to a Person object val jsonStr = """{"name":"John Smith", "age":30, "city":"New York"}""" implicit val formats = DefaultFormats val person = parse(jsonStr).extract[Person] print(person.age) } }
需要在pom里面加入
<dependency> <groupId>org.json4s</groupId> <artifactId>json4s-jackson_2.11</artifactId> <version>3.5.3</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.json4s</groupId> <artifactId>json4s-core_2.11</artifactId> <version>3.5.3</version> <scope>compile</scope> </dependency>
然后用 java -cp target/cgame-emotion-1.0.0-jar-with-dependencies.jar jobs.Test 才能跑成功。用下面的两个方式跑都失败:
java -cp ~/.m2/repository/\*:target/cgame-emotion-1.0.0.jar jobs.Test export CLASSPATH=~/./m2/repository/* java -cp target/cgame-emotion-1.0.0.jar jobs.Test
其中第二个方式里面,无论是细化到org.json4s还是更深入都会失败
标签:cgame,jobs,项目,scala,jar,json,json4s,Test,org From: https://www.cnblogs.com/kunrenzhilu/p/17259915.html