Play! 2 Framework - Add Java Mongo driver

泄露秘密 提交于 2019-12-06 11:50:18

问题


I am trying to use the java mongo driver with Play!.

So I read though:

http://www.playframework.org/documentation/2.0.2/SBTDependencies

http://www.mongodb.org/display/DOCS/Java+Tutorial

I added the buildpath in eclipse. But play can't find the dependency.

So there is an example on the playframework homepage but I still can't figure it out.

val appDependencies = Seq(

      "org.scala-tools" %% "scala-stm" % "0.3",
      "org.apache.derby" % "derby" % "10.4.1.3" % "test"

    ) 

Why are der two% signs? How do I get the correct names? I only know that the version should be 2.8.0. So if I want to add the Java driver, what do I have to do?

And if i use the official java driver, I don't have to use Morphia right?

Installing play framework mongodb morphia module

.

.

Edit:

import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

    val appName         = "website"
    val appVersion      = "1.0-SNAPSHOT"

    val appDependencies = Seq(
        "org.mongodb" % "mongo-java-driver" % "2.8.0"
        //"com.mongodb" % "Mongo" %"2.8.0"

    )

    val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
      // Add your own project settings here      
    )

}

回答1:


To add the MongoDB drivers to your Play project, edit your project/Build.scala file to add the MongoDB dependency:

val appDependencies = Seq(

   // ... here are your previous dependencies (derby etc...)
   "org.mongodb" % "mongo-java-driver" % "2.8.0"

) 

After you add this, you need to restart your Play server for the changes to take affect.




回答2:


I use reactive-mongo for my project. You can find some information here http://reactivemongo.org/releases/0.10.5/documentation/tutorial/setup.html




回答3:


In case the accepted answer doesn't work for some of you , you can try adding this version of mongodb in the build.sbt

"org.mongodb.morphia" % "morphia" % "0.107"


来源:https://stackoverflow.com/questions/11751162/play-2-framework-add-java-mongo-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!