39

I just moved from Netbeans to Eclipse. In Netbeans, I can debug Playframework applications out of the box. However, in Eclipse, it seems hard to configure this in order to debug a web app (a Playframework app in specific).

As in Play! documentation,

The main launcher in only usable with the Run As eclipse command. You can then use the “Connect JPDA launcher” using “Debug As” to start a debugging session at any time. Stopping the debugging session will not stop the server.

However, I can not see “Connect JPDA launcher” in "Debug As" (I'm using Eclipse Classic 3.7.0). I've searched about JPDA (I'm new to Java and don't know about "main launcher" and JPDA, then config Remote Debug as instruct in http://javarevisited.blogspot.com/2011/02/how-to-setup-remote-debugging-in.html But it's returning an error:

Failed to connect to remote VM. Connection refused. Connection refused: connect

I've searched and found some suggestions like:

1.)editing catalina.bat and adding the lines : set JPDA_TRANSPORT=dt_socket ... set JPDA_ADDRESS=8000 AND 2.)Editing startup.bat call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%

Actually I don't clearly understand this and I guess it's for configuring Tomcat. However, I'm using Play! default server, checked the application.conf and sure that it's listening to port 9000 and 8000 for JPDA.

Of course, I have started the Play app before debugging, I can access the app via port 9000 normally. I'm using Win 7 with no admin rights.

Do you have a detailed guide on debugging Play! in Eclipse?

Tommi
  • 8,450
  • 5
  • 29
  • 51
Thang Nguyen
  • 1,163
  • 4
  • 16
  • 28

7 Answers7

115

As of Play 2.0, the eclipse folder and launchers are no longer generated when you run play eclipsify. After running play eclipsify, you can debug your project in Eclipse as follows:

  1. In a console outside of eclipse, run play debug run.
  2. In Eclipse, right-click your project, then choose Debug As -> Debug Configurations...
  3. Right-click Remote Java Application, then click New.
  4. The host should already be set to localhost. Set the port to 9999 (the default port used by the play debug run command).
  5. Click Apply to save, then Debug to connect to your running Play instance.
Mansoor Siddiqui
  • 19,101
  • 9
  • 46
  • 65
31

First of all, you have created the configuration files for Eclipse by using the play eclipsify YourProject command, right? (If not, see Play framework documentation for more information.)

After that, you should have a folder named eclipse in your project. In it, you should see commands Connect JDPA to YourProject.launch, YourProject.launch and Test YourProject.launch.

Right-click on the YourProject.launch and choose Run As --> YourProject from the pop-up menu. That will start your application. When the application is running, right-click on the Connect JDPA to YourProject.launch, and choose Debug As --> Connect JDPA to YourProject.launch from the pop-up menu. That will start a debug session on your application.

Tommi
  • 8,450
  • 5
  • 29
  • 51
  • 2
    Sometime this makes trouble because the port is used. See http://play.lighthouseapp.com/projects/57987/tickets/991-uncomfortable-eclipse-launcher – niels Aug 24 '11 at 18:08
  • alternatively, talking about step 1, instead of starting the app from inside Eclipse, you can start it just from command line, e.g. `play test` (as debug is always enabled in `DEV` mode). This way it always use your existing configuration, otherwise you need to modify the generated '.launch' file for different port and or db. – ryenus Mar 07 '14 at 12:37
7

Play 2.1-RC2 : Running Play! app that is synced with Eclipse

To make the project Eclipse compatible, got he project folder and then give command ">play eclipse". Now you can add it as an existing project form eclipse.

Then to run it you have to first run start play in the project folder i.e. command "play"

This will activate play server and identify the app in the project i.e. [appname]$ now you have to just give the command "run" to see your app running on the localhost:9000 or whichever port config you have specified.

Debug mode: To run this similarly you need first give command "play" then [appname]$ "play debug run" this will by default use port 9999 so when you go to localhost:9000 in your browser and in your eclipse file -> Debug As -> Debug configuration.. -> New Remote Java Application -> connect specify port 9999 and debug

user1997292
  • 71
  • 1
  • 2
4

With activator, you'll need activator -jvm-debug <port number> ~run

0fnt
  • 6,986
  • 9
  • 42
  • 60
  • Can you please give more details? After running this command with port 9999. I get this message "Listening for transport dt_socket at address: 9999" But I am not able to connect eclipse debugger with it. I get "Failed to connect to remote VM. Connection refused. Connection refused" error. Thanks ! – Ankit Jain Jun 07 '15 at 14:18
  • I no longer have an Eclipse installation, so can't help you. Can you try this: `jdb -attach ` and see if it connects? If it does, but eclipse doesn't, then make sure you're following the rest of steps in `http://stackoverflow.com/a/10257101/247077` – 0fnt Jun 07 '15 at 23:52
4

I guess most of you are running the play framework with Typesafe Activator. If you are doing so, This may help you,

  1. activator -jvm-debug ~run

    Like : activator -jvm-debug 9999 ~run

(then It will start the debugger in 9999 port along with the app running in 9000 port.)

  1. Now go to eclipse and right click on the project name you want to debug and select Debug As -> Debug configuration.. -> (select)Remote Java Application -> new (top left an icon with tiny plus sign) -> connect specify port 9999 and debug.
Sagiruddin Mondal
  • 4,102
  • 2
  • 26
  • 43
  • I have performed same steps as you said to bebug it but still not able to debug it from eclipse. Please help me... – Keyur Ardeshana Jan 26 '16 at 06:43
  • It should be working. Is your console showing 9999 port is active? have you pinned any line for debug ? write to me withe the steps you ve followed. or email me with screen shots. – Sagiruddin Mondal Jan 28 '16 at 07:24
  • same thing as Keyur... it's maddening. I can see it connecting I can add breakpoints and even put stupid log statements in that i see outputting but it just skips right over any breakpoints.... – mschuett Feb 14 '17 at 07:43
2

As of Play 2.1.2, I was getting the 'address in use' error when running play debug run.

The fix was to edit play.bat in play-2.1.2 directory and change these two lines:

:setDebug
set JPDA_PORT=9999

to

:setDebug
set JPDA_PORT=8551

Then in Eclipse, select Debug Configurations, find "Remote Java Application", do New. Then set port to 8551. Now you can start play using

play debug run

And then in Eclipse start debugging using the debug configuration you created about.

IanRae
  • 283
  • 1
  • 2
1

If you run "play eclipsify" on the project folder, it will create two run configurations. Looking at the run configuration details, you should check if the following line (or something similar) is in the "VM arguments":

-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
-Dplay.debug=yes
-Dplay.id=test -Dapplication.path="${project_loc:NMKServer}"
-Djava.endorsed.dirs="c:\Java\play-1.2.2/framework/endorsed"
-javaagent:"c:\Java\play-1.2.2/framework/play-1.2.2.jar"

Here you can configure the debugging port. With this config, I can attach to process using the instructuctions you have.

javierhe
  • 513
  • 1
  • 5
  • 20