Hacking Play

About Play

Modules and plugins

Books

Setting up your preferred IDE

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.

Eclipse

Generate configuration

Play provides a command to simplify Eclipse configuration. To transform a Play application into a working Eclipse project, use the eclipse command:

without the source jars:

[My first application] $ eclipse

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] $ eclipse with-source=true

Note if you are using sub-projects with aggregate, you would need to set skipParents appropriately:

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).

To debug, start your application with play debug run and 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 9999 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.

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.

IntelliJ

Intellij IDEA lets you quickly create a Play application without using a command prompt. You don’t need to configure anything outside of the IDE, the SBT build tool takes care of downloading appropriate libraries, resolving dependencies and building the project.

Before you start creating a Play application in IntelliJ IDEA, make sure that the latest Scala (if you develop with Scala) andPlay 2 plugins are enabled in IntelliJ IDEA.

To create a Play application:

Open New Project wizard, select Play 2.x under Scala section and click Next.

Enter your project’s information and click Finish.

IntelliJ IDEA creates an empty application using SBT.

You can also import an existing Play project.

To import a Play project:- Open Project wizard, select Import Project.- In the window that opens, select a project you want to import and click OK.- On the next page of the wizard, select Import project from external model option, choose SBT project and click Next.- On the next page of the wizard, select additional import options and click Finish.

Check the project’s structure, make sure all necessary dependencies are downloaded.You can use code assistance, navigation and on-the-fly code analysis features.

You can run the created application and view the result in the default browser http://localhost:9000.

To run a Play application:- In the project tree, right-click the application.- From the list in the context menu, select Run Pla2 App.

You can easily start a debugger session for a Play application using default Run/Debug Configuration settings.

For more detailed information, see the Play Framework 2.x tutorial at the following URL:

Start ENSIME

From Emacs, execute M-x ensime and follow the on-screen instructions.

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.