Books

Working with Play is easy. You don’t even need a sophisticated IDE, because Play compiles and refreshes the modifications you make to your source files automatically, so you can easily work using a simple text editor.

However, using a modern Java or Scala IDE provides cool productivity features like auto-completion, on-the-fly compilation, assisted refactoring and debugging.

Also, if you did not want to trigger a compilation before running eclipse, then just add the following to your settings:

EclipsePlugin.EclipseKeys.preTasks := Seq()

You then need to import the application into your Workspace with the File/Import/General/Existing project… menu (compile your project first).

You can also start your application with play debug run and then you can use the Connect JPDA launcher using Debug As to start a debugging session at any time. Stopping the debugging session will not stop the server.

Tip: You can run your application using ~run to enable direct compilation on file change. This way scala template files are auto discovered when you create a new template in view and auto compiled when the file changes. If you use normal run then you have to hit Refresh on your browser each time.

If you make any important changes to your application, such as changing the classpath, use eclipse again to regenerate the configuration files.

Tip: Do not commit Eclipse configuration files when you work in a team!

The generated configuration files contain absolute references to your framework installation. These are specific to your own installation. When you work in a team, each developer must keep his Eclipse configuration files private.

Play provides a command to simplify Intellij IDEA configuration. To transform a Play application into a working IDEA module, use the idea command:

without the source jars:

[My first application] $ idea

if you want to grab the available source jars (this will take longer and it’s possible a few sources might be missing):

[My first application] $ idea with-sources=yes

This will create the configuration files IntelliJ needs to open your play application as a project. The files are named .iml and -build.iml. The file menu (IntelliJ 11.1 CE) contains the Open Project command.

Tip: There is an Intellij IDEA issue regarding building Java based Play2 apps while having the Scala plugin installed. Until it’s fixed, the recommended workaround is to disable the Scala plugin.

To debug, first add a debug configuration

Open Run/Debug Configurations dialog, then click Run -> Edit Configurations

Add a Remote configuration, then select Remote

Configure it:

Set a name

Transport: Socket

Debugger mode: Attach

Host: localhost

Port: 9999

Select module you imported

Close dialog - click Apply

Start play in debug mode (in a separate command line console, NOT in IDEA’s Play console):

$ play debug

which should print:

Listening for transport dt_socket at address: 9999

Set some breakpoints then start your new debug configuration from within IDEA. The console output should be:

That’s all there is to it. You should now get type-checking, completion, etc. for your Play project. Note, if you add new library dependencies to your play project, you’ll need to re-run “ensime generate” and re-launch ENSIME.