5
votes

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!

2
Are you by chance defining your own package play? That would shadow the Play framework.0__
Thanks, but no:(. I've edited the post to include how the controller's file looks like.Jacob

2 Answers

6
votes

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

1
votes

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