playframework Eclipse as Play IDE - Java, Play 2.4, 2.5


Example

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 http://scala-ide.org/download/sdk.html.

Setting eclipse IDE per project

To import Play application into eclipse:

  1. Add eclipse plugin into project/plugins.sbt:
//Support Play in Eclipse
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")
  1. Add into build.sbt a flag that forces compilation to happen when the eclipse command is run:
EclipseKeys.preTasks := Seq(compile in Compile)
  1. 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](-[classifier]).[ext]
activator-launcher-local: file:////${activator.local.repository-${activator.home-${user.home}/.activator}/repository}, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
  1. Compile the application:
activator compile
  1. 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

  1. Add to the build.sbt:
EclipseKeys.withSource := true
  1. Compile the project

Setting eclipse IDE globally

Add the sbt user setting:

  1. 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
  1. Add eclipse plugin into plugins.sbt:
//Support Play in Eclipse
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")
  1. Create in user .sbt directory a file sbteclipse.sbt. For example for Windows user asch:
c:\asch\.sbt\0.13\sbteclipse.sbt
  1. 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)
  1. 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:

  1. Right-click on the project and select Debug As, Debug Configurations.
  2. In the Debug Configurations dialog, right-click on Remote Java Application and select New.
  3. 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.