Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug Play application using activator?

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?

like image 421
abourg28 Avatar asked Oct 20 '13 04:10

abourg28


4 Answers

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!

like image 92
2 revs Avatar answered Nov 13 '22 19:11

2 revs


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.

like image 43
Readren Avatar answered Nov 13 '22 19:11

Readren


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.

like image 4
user3791111 Avatar answered Nov 13 '22 21:11

user3791111


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

like image 4
user1242321 Avatar answered Nov 13 '22 20:11

user1242321