Setup Play Framework with Scala in IntelliJ

UPDATE: This is only for Play 1.x with Scala. Getting Play 2 projects (Java or Scala) working in IDEA is now as easy running “play idea” and then opening the project.

Update 2: I’ve posted a new video showing how to create and run Play2 apps in IntelliJ.

Yesterday at the [Programming Summer Camp][1] a group of us were working together to learn the [Play Framework][2]. Once we were able to get the basics working we wanted to get everything working in [IntelliJ IDEA][3]. Due to a lack of good documentation on the subject things did not go smoothly until we figured out the right “magical incantations”. We did eventually get it working so I wanted to document the steps we took.

  1. Add Scala support to Play: ```bash play install scala

  2. Create a new Play project with Scala support: ```bash
play new foo --with scala
  1. Have Play create an IntelliJ Module Descriptor: ```bash play idealize foo

  4. Run the app: ```bash
play run foo
  1. Access the app in a browser to generate some source files we will use later:
  1. Shutdown the Play server.
  2. Currently the Play Scala Module (version 0.9.1) only supports Scala 2.8.1 so [download][4] and extract that version.
  3. Create a new project (from scratch) in IntelliJ. The location should be the same as the directory where the Play project was created. Un-check the “Create module” option.
  4. In the Project Structure window, with “Modules” selected, click the “+” button to add a new module to the project.
  5. Select the “Import existing module” option and then point it to the generated .iml file.
  6. With the module now selected, select the content root block for the module (mine is /home/jamesw/projects/foo). Then select the “tmp/generated” directory in the tree on the right and press the “Sources” button. The HTML template pages are converted to .scala source files by Play and we need these source files to be included in the project along with the regular source files in the app directory.
  7. Select “Global Libraries” in the Platform Settings on the left and add a new Java Library named “scala-compiler-2.8.1”. Then press the “Attach Classes…” button and navigate to the “lib” directory in your Scala 2.8.1 directory. Then select the “scala-compiler.jar” and “scala-library.jar” files.
  8. Add another Global Library named “scala-library-2.8.1” containing the “scala-dbc.jar”, “scala-library.jar”, and “scala-swing.jar” files.
  9. Press the “Apply” button to save the Global Libraries configuration.
  10. Select “Modules” and then the “Dependencies” tab. Press the “Add…” button and select “Library” to add a new library to the module. Select “scala-library-2.8.1” and then press the “Add Selected” button to add it to the Dependencies.
  11. Select the “Scala” Facet in the module and set the Compiler library to the “scala-compiler-2.8.1” option.
  12. Save the Project Structure by pressing the “Ok” button. Make sure the project now builds without any errors.
  13. To run the Play server from IntelliJ a new Run Configuration must be configured. To create a new Run Configuration select “Run” from the main IntelliJ menu and then select “Edit Configurations”.
  14. Press the “+” button and select “Application” from the list of Run Configuration types.
  15. Set the name to “Play Server”.
  16. Set the Main class to “play.server.Server”.
  17. Set the VM Parameters to: ```bash -Dapplication.path="."

 23. De-select the "Make" option in the "Before Launch" section.
 24. Press the "Ok" button to save the configuration. <img src="" alt="" title="Run Configuration" width="697" height="650" class="alignnone size-full wp-image-2501" srcset=" 697w, 300w" sizes="(max-width: 697px) 100vw, 697px" />
 25. Run the Play Server by selecting "Run" from the "Run" IntelliJ menu and verify that the application still works by opening the application in a browser.

It is so much easier to figure this stuff out with a group of people. That is just one of the many reasons why the Programming Summer Camp is a great event!

Let me know if you have any questions or problems.