我创建了一个简单的项目。
“sbt run”工作正常。
在我运行“sbt package”后出现 jar 文件,但它不起作用。
$ scala target/scala-2.9.2/hello_2.9.2-0.1.jar
出现以下错误:
java.lang.NoClassDefFoundError: com/mongodb/DBObject
这是我的文件:
你好.scala
package greeter
object Hello extends App {
import com.mongodb.casbah.Imports._
val mongoClient = MongoClient()
println("Connected to MongoDB")
val collection = mongoClient("test")("foo")
val doc = MongoDBObject("msg" -> "Hi from Scala!")
collection.insert(doc)
println("Doc inserted");
}
构建.sbt
name := "hello"
mainClass := Some("greeter.Hello")
version := "0.1"
scalaVersion := "2.9.2"
libraryDependencies += "org.mongodb" % "casbah_2.9.2" % "2.5.0"
resolvers += "snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
resolvers += "releases" at "https://oss.sonatype.org/content/groups/scala-tools"