Wednesday, June 8, 2016

Using eclipse as Play IDE

Working with Play may be done with a simple text editor and activator UI. Yet it is hard to imagine that this happens in practice. Play has several plugins for different IDE-s. The eclipse plugin allows to transform a Play project into an eclipse project with the command sbt 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

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")
2. Add into build.sbt a flag that forces compilation to happen when the eclipse command is run:
EclipseKeys.preTasks := Seq(compile in Compile)
3. 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]
4. Compile the application:
activator compile
5. 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
2. 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 ala:
2. Add eclipse plugin into plugins.sbt:
//Support Play in Eclipse
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")
3. Create in user .sbt directory a file sbteclipse.sbt. For example for Windows user ala:
4. 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)
5. Add optionally other EclipseKeys settings.

Converting to maven project

See the post Creating of a maven project for Play application

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.

No comments :

About the author

My Photo
I trust only simple code and believe that code should be handsome. This is not a matter of technology, but professional approach, consolidated after years of software development. I enjoy to cause things working and feel very happy, when I manage to solve a problem.
Back to Top