How to debug Play application using activator?

前端 未结 5 1297
感动是毒
感动是毒 2021-01-30 17:17

I know that for the classic Play framework it\'s play debug ~run. I tried running activator debug ~run but I get the following error:

[         


        
相关标签:
5条回答
  • 2021-01-30 17:55

    With the Play framework 2.x:

    Inside your project directory, run the activator command like

    activator -jvm-debug 9999 run

    Once this is done, debug your project as Remote Java Application within your IDE to hook it with the activator process.

    Once this is done, you shall be able to break in your code anywhere. :)

    0 讨论(0)
  • 2021-01-30 17:57

    If you're just doing activator ~run, then you should be able to pass a JVM debug port option with:

    ./activator -jvm-debug <port> ~run
    

    This may not do the same thing as play-run, but here's the arguments it's adding to the command line:

    -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=<port>
    

    From: https://github.com/typesafehub/activator/blob/master/dist/src/templates/activator#L107

    I've successfully attached to this process in my IDE.

    If you're running in windows, the automatic configuration is a bit different. With the latest activator, you can do the following:

    1. Open %UserProfile%\.activator\activatorconfig.txt (The UserProfile is different depending on your windows install. Mine is C:\Documents and Settings\jsuereth on one installation and C:\Users\jsuereth on another). Past the following in the file: -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=<PUT YOUR PORT HERE>
    2. You can set the JAVA_OPTS property on the command line before starting activator, e.g. set "JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=<port>"

    Hope that helps!

    0 讨论(0)
  • 2021-01-30 18:01

    I tried Readren's solution but using IntelliJ IDEA community edition (so no inbuilt Play support) instead of Eclipse.

    This is basically the way it is documented to work with the new Typesafe Activator stuff (I'm using 1.3.2). For me application ran and the IntelliJ debugger looked like it was connecting but it would not hit any breakpoints (also the breakpoints in IntelliJ did not have a tick mark indicating they were not going to get hit).

    I tried changing the DEBUG_OPTS setup in the activator.bat file to use the -agentlib form of the jdwp command line arguments and this seemed to fix it for me.

    rem set DEBUG_OPTS=-Xdebug -Xrunjdwp:tnsport=dt_socket,server=y,suspend=n,address=!JPDA_PORT!
    set DEBUG_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9999
    

    Probably I should put this in an activatorconfig.txt somewhere but spent about 4 hours trying to get this to work - so it's good enough for me now...

    I'm using the following JVM in case it matters:

    java version "1.7.0_75" Java(TM) SE Runtime Environment (build 1.7.0_75-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

    0 讨论(0)
  • 2021-01-30 18:15

    I have windows7 and activator 1.2.12, and the answers above didn't work for me. Instead, I used the "-jvm-debug" option of the "activator.bat" command of the project home folder, and it worked. Like this:

    C:\Projects\MyProject>activator -jvm-debug
    Listening for transport dt_socket at address: 9999
    [info] Loading global plugins from C:\Users\MyAccount\.sbt\0.13\plugins
    [info] Loading project definition from C:\Projects\MyProject\project
    [info] Set current project to MyProject (in build file:/C:/Projects/MyProject/)

    Then, inside the activator (sbt), I used the "run" command. Like this:

    [MyProject] $ run
    
    --- (Running the application, auto-reloading is enabled) ---
    
    [info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
    'force' enabled
    
    (Server started, use Ctrl+D to stop and go back to the console...)
    
    Running "watch" task

    To debug from 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.

    0 讨论(0)
  • 2021-01-30 18:15

    Another thing that I discovered:

    fork in run := false
    
    fork in Test := false
    

    in "build.sbt".

    This enables you to debug your tests, not only the application itself.

    0 讨论(0)
提交回复
热议问题