How to run Play Framework 2.x in debug mode in IntelliJ IDEA?
Asked Answered
V

5

14

I want to run Play Framework 2.x in debug mode in IntelliJ IDEA. I searched in the Internet and all results say that you have to use play console.

Is it possible to run in debug mode in IntelliJ IDEA without using play console?

Variscite answered 14/6, 2014 at 9:4 Comment(1)
You can find your answer in the last. #24218841Fax
L
11

You need to use Idea 12+ Ultimate Edition

  • Install Play 2.0 Support, Scala and other required plugins in Idea
  • In command line perform play idea to generate project
  • Open created project in Idea (open, don't import)
  • Go to: Menu > Run > Edit Configurations... > Add New Configuration... > choose Play 2 App
  • In Menu > Run new buttons will appear Debug and Run, first will run app with enabled debbuger.
Lorylose answered 14/6, 2014 at 9:24 Comment(2)
Why is play idea required since IDEA supports play/sbt projects?Chlamydeous
How does it work with Idea 16. In version 14 I had done the same, but I cant find Play in the debug config.Bagpipes
S
30

Using activator :

  1. From Terminal (Not intellij terminal), enter command : activator ui
  2. Open your existing app
  3. Choose "Code view & Open in IDE
  4. In Browse Code, click setting icon
  5. Choose Open Project in Intellij IDEA
  6. Generate

  7. Open Intellij IDEA

  8. Open project - browse your app directory
  9. Run - Edit Configuration
  10. Add new configuration - Remote
  11. Add name Setting transport : socket, debugger mode : attach, Host : localhost, port : 9999 module clashpath : your app
  12. Tools - Open Terminal
  13. activator -jvm-debug 9999 run
  14. Run debug
  15. Open browser localhost:9000
Semifluid answered 15/6, 2014 at 2:46 Comment(3)
Small error on step-11, the port should be '9999' if you start the jvm debugger with port '9999'Libau
In Play 2.5 at least, I also had to edit build.sbt and make sure it had 'fork in run := false'Campus
same, can't get this to work also have fork in run set to false. I'm sure i'm doing something wrong but 3 hours on SO haven't turned up anything.Dooryard
L
11

You need to use Idea 12+ Ultimate Edition

  • Install Play 2.0 Support, Scala and other required plugins in Idea
  • In command line perform play idea to generate project
  • Open created project in Idea (open, don't import)
  • Go to: Menu > Run > Edit Configurations... > Add New Configuration... > choose Play 2 App
  • In Menu > Run new buttons will appear Debug and Run, first will run app with enabled debbuger.
Lorylose answered 14/6, 2014 at 9:24 Comment(2)
Why is play idea required since IDEA supports play/sbt projects?Chlamydeous
How does it work with Idea 16. In version 14 I had done the same, but I cant find Play in the debug config.Bagpipes
G
5

Preparation: Do not use the project creation by activator ui or similar. Just open the project in IntelliJ.

  1. activator -jvm-debug 9999 ~run. The ~ before run enables automatic reloading of generated HTML pages
  2. In IntelliJ:
    1. Run > Edit Configurations...
    2. Select Defaults/Remote
    3. Click on the green + at the upper left corner
    4. Give the name "Play 2"
    5. Ensure that Transport:Socket and Debugger mode:Attach are selected
    6. Type in 9999 as port Preferences Screenshot
    7. Press "OK"
  3. Run > Debug Play 2 (second entry in the list)

Pro hint: Check out the play-auto-refresh plugin to have Chrome automatically reloading on a change.

(based on @ARM's answer)

Golliner answered 17/7, 2016 at 15:40 Comment(1)
Just wow. Didnt expected to have debugging running in 2min. This man deserves an cookie!Wanitawanneeickel
F
4
  1. Open Intellij IDEA
  2. Open project - browse your app directory Run - Edit Configuration
  3. Add new configuration - Play2
  4. Add http://localhost:9000 to url to open option
  5. Add -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M to JVM option
  6. Set Debug port to 9999
  7. Set your debug point and debug your application. Cheers :)

FYI : All of the above fields might filled up already

enter image description here

Fax answered 8/3, 2016 at 14:22 Comment(2)
what does -XX:+CMSClassUnloadingEnabled do?Rushy
I removed above CMSClassUnloadingEnabled which was automatically added and were creating errors with it; removing it did not appear to have further problems.Rushy
A
3

this works for me and maybe easier

  1. file menue => settings => Build, Execution, Deployment => sbt => check "Enable debugging for sbt shell"

  2. idea sbt shell now will start with debug enable, log out the port as "Listening for transport dt_socket at address: 52701"

  3. Run/Debug Configurations => Add(the pluss(+) sign) => Remote => Set "Port" And "Use module classpath"

  4. just type run in sbt shell, then click debug button

screent shot

  1. enable idea emaded sbt debug enter image description here
  2. sbt shell start log enter image description here
  3. add remote in "Run/Debug" enter image description here
  4. type run here enter image description here
Armrest answered 27/7, 2021 at 6:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.