Thanh Le
Thanh Le

Reputation: 1388

How to run playframework sample in Intelllij 13?

I am using Intellij 13 Ultimate and want to create a Play Framework sample. But I am unable to build this project because it always throws this error:

object index is not a member of package views.html
Ok(views.html.index("Your new application is ready."))

I have tried this on both Mac and Windows platforms, but the error is always the same.

How can I solve this?

Upvotes: 5

Views: 2762

Answers (4)

Lincoln
Lincoln

Reputation: 181

I found a trick here.

If you generate the play-scala project using activator command line activator [new my_first_project play-scala]. You'll get the following sbt build file.

name := """my_first_project"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
  jdbc,
  cache,
  ws,
  "org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test
)

resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"

But IF you create a project from intellj using NewProject->Scala-Play 2.x, you will get the following sbt.

name := "my_second_project"

version := "1.0"

lazy val `my_second_project` = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq( jdbc , cache , ws   , specs2 % Test )

unmanagedResourceDirectories in Test <+=  baseDirectory ( _ /"target/web/public/test" )  

resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"  

fork in run := false

after combine them. Ignore the name. And I set for in run to false

name := "my_second_project"

version := "1.0"

lazy val `my_second_project` = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq( jdbc , cache , ws   , specs2 % Test )

unmanagedResourceDirectories in Test <+=  baseDirectory ( _ /"target/web/public/test" )  

resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"  

fork in run := false

After doing that. Open the activator-generated project with Intellj, configure a run with Play 2.x run. Everything goes well.

By the way, if you open the activator-generated project before you change the sbt file. You might need to rm -r .idea

Hope that helps.

Upvotes: 1

garbelini
garbelini

Reputation: 468

Running "play idea" in the new project root fixed it for me. The project should compile and run after reloading.

I only have this problem with projects created through Idea's New Project menu.

Upvotes: 0

arbuzz
arbuzz

Reputation: 396

I have the same problem: in Idea 13 there are highlight errors there, but in Idea 12 everything is ok. The reason is that there is no Scala plugin for Idea 13, so for now it's impossible to get it to work in Idea 13.

The solution is to install Idea 12, go to Preferences -> Plugins, type "Scala" in find box, and install Scala plugin.

Upvotes: -2

Jean
Jean

Reputation: 21595

The generation works just fine and all the paths are correctly added to the build. However the routes are not (yet) compiled by the plugins (scala+playframework), thus the reverse routing classes generated by play are not available for intellij. You will have the same problem with the templates.

If you run a play compile (or a sbt compile), the classes will be generated and intellij should be able to pick them up and compile your project.

Upvotes: 11

Related Questions