Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

object db is not a member of package play

I'm trying to make my first tests with Scala and with Play framework.

I have installed play 2.2.0, which seems to be the last version, with the standalone package. After that, I've been able to create a new application, compile and run it.

I've tried to start to use Anorm package to access to the database, but I've found a blocking error which I can't find on the docs. I don't know if that means that is so obvious, but after adding:

package controllers

import play.api._
import play.api.mvc._
import play.db.anorm._ //(this is the new line)

object Application extends Controller {
  def index = Action {
    Ok(views.html.index("Your new application is ready."))
  }
}

It fails with:

object db is not a member of package play

I've seen this:

  • https://groups.google.com/forum/#!msg/play-framework/RUbmEVsw2rY/UOE5mNs1WjoJ

Where they talk about adding the dependency to jdbc, which seems to be already in my build.sbt.

libraryDependencies ++= Seq(
  jdbc,
  anorm,
  cache
)   

I've also found this thread here:

  • play.db package not found in play 2.1.3

But I can't find a build.scala file on my project. Not using any IDE by now, just play console (run & compile commands).

Thanks a lot!

like image 273
Jacob Avatar asked Oct 26 '13 12:10

Jacob


2 Answers

In fact (as the error explains), there is no package play.db.anorm._ in version 2.2.0. Try use import anorm._ instead.

like image 69
Yall Avatar answered Sep 25 '22 15:09

Yall


You need the following libraries

slick
play-jdbc
anorm

This is how my dependencies look like in build.sbt :

libraryDependencies ++= Seq(
  "com.typesafe.slick" % "slick_2.10" % "2.1.0",
  "org.postgresql" % "postgresql" % "9.4-1201-jdbc41",
  "com.typesafe.play" % "play-jdbc_2.10" % "2.4.0-RC1",
  cache,
  anorm
)

Search for the latest version of library at Maven Central Repository

like image 37
Hanxue Avatar answered Sep 24 '22 15:09

Hanxue