IntelliJ IDEA 2021.2 Help

Getting started with Play 2.x

Before you start generating your Play project, make sure that the Scala plugin is downloaded and enabled in IntelliJ IDEA.

IntelliJ IDEA supports Play versions 2.4 and later.

Let's look at the following common scenarios for generating a Play 2 project in IntelliJ IDEA:

  • If you have an already existing Play 2 project, you can import it or check out from version control. In this case you can follow the regular procedure for importing or cloning a project.

  • If you are not familiar with Play 2 framework and want to learn how to use it, create a Play project via IntelliJ IDEA that will generate an executable application.

  • If you want to see what types Play 2 projects can be generated, use Lightbend Project Starter and create a project using one of the offered templates.

  • If you want to manually add a support for Play 2 framework, create an sbt project.

Create a new Play 2 project

  1. Open New Project wizard. From the options on the right, select Play 2.x.

    New Project dialog
  2. Follow the steps suggested in the wizard and click Finish.

IntelliJ IDEA generates the Play 2 project with the appropriate structure, dependencies and an executable application.

Play 2 project editor and tool windows

Create a Play 2 template with Lightbend project starter

  1. Open a new project wizard and from the options on the right, select Lightbend Project Starter.

    Lightbend project starter
  2. On the next page of the wizard select a template that you want to use for your project. For example, select the Play Scala Seed template that will create an executable Play template project for developing your Play application.

    New Project dialog

    Click Finish.

Create an sbt project with Play 2 framework

  1. Create an sbt project.

    Sbt project create

    Follow the steps suggested in the wizard and click Finish.

    IntelliJ IDEA creates an sbt project.

  2. Open the build.sbt file in the editor and add Play as a project dependency.

    libraryDependencies ++=Seq("" %% "play" % "2.7.3")
  3. In the Project tool window, in the project source root directory, select New | File to create the plugins.sbt file.

  4. Open the plugins.sbt file in the editor and add the Play 2 plugin.

    addSbtPlugin("" % "sbt-plugin" % "2.7.3")

IntelliJ IDEA downloads the appropriate dependencies and adds them to the Dependencies node in the sbt projects tool window.

sbt tool window

Please note that the Play 2 framework project structure is not generated and you need to add everything manually. Check the Play 2 project structure.

At this point you can start creating Play 2 templates since IntelliJ IDEA supports them as soon as support for Play 2 framework is added and develop your project further. You can use code completion, navigation and on-the-fly code analysis features in your Play 2 files. IntelliJ IDEA also supports code assistance for routes files and code inspections.

Open an existing Play 2 project

  1. On the welcome screen, select Open. Alternatively, from the main menu, select File | Open.

  2. In the dialog that opens, locate your project and if it is an sbt project, select the build.sbt file and click Open.

  3. In the dialog that opens, click Open as Project.

    IntelliJ IDEA opens the project and loads all the necessary dependencies.

    If your project is not an sbt project, refer to the import project section.

Run and debug Play 2 application

  1. If you want to run the application:

    1. In the project tool window, right-click the application.

    2. In the context menu, select Run Play 2 App.

  2. If you need to access the Run/Debug Configurations dialog:

    1. On the main menu, select Run | Edit Configurations.

    2. Click the Icons general add and select Play 2 App to create a new configuration.

    3. Specify run/debug configuration settings. The default settings are enough for running and debugging purposes.

      Play run debug
    4. On the main toolbar, click the Icons toolwindows tool window run icon to run or the Icons actions start debugger icon to debug your application.

You can check the output of your application in the default browser http://localhost:9000. If you want to stop the server session, press Alt+D (Cmd+P for macOS).

Play server display

Work with Play2 settings

You can use Play 2 settings to configure compiler options and configure formatting for route files. You can also view and edit a list of default template imports.

  1. Press Ctrl+Alt+S and from the options on the left select Languages   Frameworks | Play2.

  2. Depending on what settings you want to configure, on the Play2 settings page, select the appropriate tab and adjust the settings. Use the Other tab to check and edit the list of template imports that get retrieved from the descriptor when you refresh your project.

    Play settings

    To manually add a template, delete, or edit the existing ones, select the Select template imports manually option so the Imports section becomes active and adjust the list of imports accordingly.

Last modified: 02 August 2022