Reputation: 733
I am making a Scala application using Play, and I want to connect to my Cassandra cluster, but I have no clue on how to do that. I'm trying to use the Datastax server, as I read here that that is the way to go and I'm already familiar with it since I've also used it in Java. But I'm stuck as to how to use it.
My build.sbt file looks like this:
name := """my-first-app"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
"com.datastax.cassandra" % "cassandra-driver-core" % "2.0.2",
jdbc,
anorm,
cache,
ws)
As a test, I tried to import some of it in my code using:
import com.datastax.driver.core.Cluster;
Complete code looks like this (application.scala)
package controllers
import play.api._
import play.api.mvc._
import com.datastax.driver.core.Cluster;
object Application extends Controller {
def index = Action {
Ok(views.html.index("Your new application is ready."))
}
}
But whe I run the application I receive the following error message:
object datastax is not a member of package com
I have no idea what is going wrong here. I checked out another project that also uses Cassandra and they appear to be doing it in the same way.
Upvotes: 2
Views: 1806
Reputation: 74729
Do reload
in your sbt
or activator
shell or close the session and start over. It just works with the build you've showed in the question.
As an additional check if the build with the Cassandra dependency has been loaded, execute show libraryDependencies
that is going to show you the dependencies of your project.
[play-2.3] $ show libraryDependencies
[info] List(org.scala-lang:scala-library:2.11.2, com.typesafe.play:twirl-api:1.0.2,
com.typesafe.play:play:2.3.4, com.typesafe.play:play-test:2.3.4:test,
com.typesafe.play:play-docs:2.3.4:docs, org.webjars:bootstrap:3.2.0,
org.webjars:jquery:2.1.1, org.webjars:requirejs:2.1.14,
org.webjars:rjs:2.1.15:test, org.webjars:squirejs:0.1.0:test,
com.datastax.cassandra:cassandra-driver-core:2.1.1)
Upvotes: 3