Setting up your preferred IDE
IntelliJ IDEA
Prerequisites
- Intellij IDEA installed (Community or Ultimate edition)
- Scala Plugin installed in IntelliJ
- A standard Play project, created for instance with Activator (
activator new [nameoftheproject] play-scala)
.
Opening the project
- Open IntelliJ IDEA
- Go to menu
File
>Open ...
> click the whole folder [nameoftheproject] >OK
- A popup opens with a few options. The default values are good enough in most cases, and if you don’t like them you can change them somewhere else later. Click
OK
- Intellij IDEA will think a bit, then propose another popup to select which modules to select in the project. There should be two modules
root
androot-build
selected by default. Don’t change anything and clickOK
. - IntelliJ will open the project. You can start viewing the files while IntelliJ keep thinking a bit as you should see in the status bar in the bottom, then it should finally be fully ready.
Running the applications from Intellij
From there some people use the IDE just to view/edit the project, while using the sbt
command line to compile/run/launch tests. Others prefer to launch those from within Intellij. It is required if you want to use the debug mode. Steps :
- Menu
Run
>Edit configurations...
- In the popup, click the
+
in the top left > ChoosePlay 2 App
in the list - Name the configuration, for instance [nameofyourproject]. Leave the default options and hit
OK
. - From the
Run
menu, or the buttons in the UI, you can nowRun
orDebug
using this configuration.Run
will just launch the app, as if you didsbt run
from the command line.Debug
will do the same thing but allow you to place breakpoints in the code to interrupt the execution and analyze what’s happening.
Auto-import option
This is an option global to the project, that is available at creation time and afterwards can be changed in the menu Intellij IDEA
> Preferences
> Build, Execution, Deployment
> Build tools
> SBT
> Project-level settings
> Use auto-import
.
This option has nothing to do with the import
statements in the Scala code. It dictates what Intellij IDEA should do when you edit the build.sbt
file. If auto-import is activated, Intellij IDEA will parse the new build file immediately and refresh the project configuration automatically. It gets annoying quickly as this operation is expensive and tends to slow Intellij when you’re still working on the build file. When auto-import is desactivated, you have to indicate manually to Intellij that you edited the build.sbt
and would like the project configuration to be refreshed. In most cases a temporary popup will appear to ask you if you would like to do so. Otherwise go to the SBT panel in the UI, and click the blue circling arrows sign to force the refresh.
Eclipse as Play IDE - Java, Play 2.4, 2.5
Introduction
Play has several plugins for different IDE-s. The eclipse plugin allows to transform a Play application into a working eclipse project with the command activator eclipse. Eclipse plugin may be set per project or globally per sbt user. It depends on team work, which approach should be used. If the whole team is using eclipse IDE, plugin may be set on a project level. You need to download eclipse version supporting Scala and Java 8: luna or mars - from https://scala-ide.org/download/sdk.html.
Setting eclipse IDE per project
To import Play application into eclipse:
-
Add eclipse plugin into project/plugins.sbt:
//Support Play in Eclipse addSbtPlugin(“com.typesafe.sbteclipse” % “sbteclipse-plugin” % “4.0.0”)
-
Add into build.sbt a flag that forces compilation to happen when the eclipse command is run:
EclipseKeys.preTasks := Seq(compile in Compile)
-
Make sure, that a user repository path in the file {user root}.sbt\repositories has the proper format. The proper values for properties activator-launcher-local and activator-local should have at least three slashes like in the example:
activator-local: file:////${activator.local.repository-C:/Play-2.5.3/activator-dist-1.3.10//repository}, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/artifact.[ext] activator-launcher-local: file:////${activator.local.repository-${activator.home-${user.home}/.activator}/repository}, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/artifact.[ext]
-
Compile the application:
activator compile
-
Prepare an eclipse project for the new application with:
activator eclipse
Now the project is ready to be imported into eclipse via Existing Projects into Workspace.
How to attach Play source to eclipse
-
Add to the build.sbt:
EclipseKeys.withSource := true
-
Compile the project
Setting eclipse IDE globally
Add the sbt user setting:
-
Create under the user root directory a folder .sbt\0.13\plugins and a file plugins.sbt. For example for Windows user asch:
c:\asch.sbt\0.13\plugins\plugins.sbt
-
Add eclipse plugin into plugins.sbt:
//Support Play in Eclipse addSbtPlugin(“com.typesafe.sbteclipse” % “sbteclipse-plugin” % “4.0.0”)
-
Create in user .sbt directory a file sbteclipse.sbt. For example for Windows user asch:
c:\asch.sbt\0.13\sbteclipse.sbt
-
Put into sbteclipse.sbt a flag that forces compilation to happen when the activator eclipse command is run:
import com.typesafe.sbteclipse.plugin.EclipsePlugin.EclipseKeys EclipseKeys.preTasks := Seq(compile in Compile)
-
Add optionally other EclipseKeys settings.
Debugging from eclipse
To debug, start the application with the default port 9999:
activator -jvm-debug run
or with the different port:
activator -jvm-debug [port] run
In eclipse:
- Right-click on the project and select Debug As, Debug Configurations.
- In the Debug Configurations dialog, right-click on Remote Java Application and select New.
- Change Port to relevant (9999 if the default debug port was used) and click Apply.
From now on you can click on Debug to connect to the running application. Stopping the debugging session will not stop the server.
Eclipse IDE
Prerequisites
- Java8 (1.8.0_91)
- Eclipse neon (JavaScript and Web Developer)
- Play Framework 2.5.4
Installing Scala in Eclipse
- Launch the Eclipse
- Open
Help
>Eclipse Marketplace
- Type
Scala
inFind
- Install Scala IDE
Setup sbteclipse
- Open play project
.\project\ plugins.sbt
- Add following command in
plugins.sbt
to convert eclipse project
addSbtPlugin(“com.typesafe.sbteclipse” % “sbteclipse-plugin” % “4.0.0”)
- Open command and go to play project e.g.
cd C:\play\play-scala
. Type following at command line
activator eclipse
Importing project
- Go to menu
File
>Import
in Eclipse - Select
Existing Projects into Workspace
- Select root directory
Now your project is ready to view and edit at Eclipse IDE.