Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 537
Thanh Le Avatar asked Dec 12 '13 02:12

Thanh Le


People also ask

How do I run a framework project in IntelliJ?

Open an existing Play 2 projectIn the dialog that opens, locate your project and if it is an sbt project, select the build. sbt file and click Open. In the dialog that opens, click Open as Project. IntelliJ IDEA opens the project and loads all the necessary dependencies.

How do I run a piece of code in IntelliJ?

To run a script, open it in the editor or select it in the Project tool window, and then select Run <script file name> from the context menu.

How do I get the run option in IntelliJ?

From the main menu, select Run | Edit Configurations. Alternatively, press Alt+Shift+F10 , then 0 . Select the run/debug configuration you want to share, enable the Store as project file option, and specify the location where the configuration file will be stored.


2 Answers

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.

like image 139
Jean Avatar answered Nov 15 '22 03:11

Jean


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.

like image 39
Lincoln Avatar answered Nov 15 '22 03:11

Lincoln