object db is not a member of package play
Asked Answered
C

2

5

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:

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:

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!

Counterpart answered 26/10, 2013 at 12:48 Comment(2)
Are you by chance defining your own package play? That would shadow the Play framework.Enforce
Thanks, but no:(. I've edited the post to include how the controller's file looks like.Counterpart
F
6

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

Firebreak answered 26/10, 2013 at 16:30 Comment(1)
Thanks Yall, that was all. Seems that part of the docs/tutorials still have references to the previous import.Counterpart
O
1

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

Oosperm answered 29/4, 2015 at 8:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.