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] a group of us were working together to learn the [Play Framework]. Once we were able to get the basics working we wanted to get everything working in [IntelliJ IDEA]. 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.
- Add Scala support to Play: ```bash play install scala
2. Create a new Play project with Scala support: ```bash play new foo --with scala
- Have Play create an IntelliJ Module Descriptor: ```bash play idealize foo
4. Run the app: ```bash play run foo
- Access the app in a browser to generate some source files we will use later:
- Shutdown the Play server.
- Currently the Play Scala Module (version 0.9.1) only supports Scala 2.8.1 so [download] and extract that version.
- 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.
- In the Project Structure window, with “Modules” selected, click the “+” button to add a new module to the project.
- Select the “Import existing module” option and then point it to the generated .iml file.
- 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.
- 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.
- Add another Global Library named “scala-library-2.8.1” containing the “scala-dbc.jar”, “scala-library.jar”, and “scala-swing.jar” files.
- Press the “Apply” button to save the Global Libraries configuration.
- 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.
- Select the “Scala” Facet in the module and set the Compiler library to the “scala-compiler-2.8.1” option.
- Save the Project Structure by pressing the “Ok” button. Make sure the project now builds without any errors.
- 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”.
- Press the “+” button and select “Application” from the list of Run Configuration types.
- Set the name to “Play Server”.
- Set the Main class to “play.server.Server”.
- 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="http://www.jamesward.com/wp/uploads/2011/07/9.png" alt="" title="Run Configuration" width="697" height="650" class="alignnone size-full wp-image-2501" srcset="https://www.jamesward.com/uploads/2011/07/9.png 697w, https://www.jamesward.com/uploads/2011/07/9-300x279.png 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. : https://sites.google.com/site/programmingsummercamp/ : http://www.playframework.org/ : http://www.jetbrains.com/idea/ : http://www.scala-lang.org/node/165