How to debug Play application using activator?
Asked Answered
P

5

30

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:

[error] Not a valid command: debug (similar: idea)
[error] Not a valid project ID: debug
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: debug (similar: debianSign, node)
[error] debug
[error]      ^

What am I doing wrong?

Paragon answered 20/10, 2013 at 4:29 Comment(3)
This is a bug in Activator: github.com/typesafehub/activator/issues/109Mcmanus
Looks like the bug is only for the Activator UI, not the CLI.Mcmanus
The issue happens also when calling the activator CLI (1.2.2) from within Jenkins launcher (not in a Batch or Shell build).Closeup
L
59

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!

Lovett answered 20/10, 2013 at 4:29 Comment(3)
Are you on windows or linux? For windows, it's a different hook.Lovett
Ah! I'm on windows. What should I be using on windows?Paragon
Sorry for the big delay. Regarding #1 I don't have the activatorconfig.txt. I even searched my C drive for it. However regarding #2 it worked! I can finally debug. Thanks a bunch!Paragon
G
4

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.

Gargle answered 8/3, 2015 at 18:10 Comment(0)
G
4

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.

Gertiegertrud answered 20/7, 2015 at 9:54 Comment(0)
I
4

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. :)

Illfavored answered 20/2, 2016 at 0:18 Comment(1)
That worked for me. Sad that there is no shorthand notation like it used to be back when activator was not introduced in Play projects.Gothic
C
0

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)

Crossbred answered 25/4, 2015 at 22:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.