We help IT Professionals succeed at work.

remote debugging in eclipse

gudii9
gudii9 asked
on
459 Views
Last Modified: 2014-08-28
Hi,

I am going through below link
http://javarevisited.blogspot.com/2011/02/how-to-setup-remote-debugging-in.html

I would like to try the remote debugging on eclipse i have on my laptop. How do i start and proceed. Please advise
Comment
Watch Question

Amitkumar PSr. Consultant
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
3. Open that program (Test.java) file and set the breakpoint. You will see whenever control goes to that line, debugger will stop and you can then proceed further.

When i put  breakpoint eclipse automatically stops control at the break point right. How above point 3 is related with below point number 1, 2. please advise

1. create a simple program, compile it and then execute it from command prompt and add below params while executing the command.

Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y  suspend=y

So for example your program name is Test.java
java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y  suspend=y Test

2. Keep the program running in command prompt and follow the steps to setup remote debugging in Eclipse mentioned in that web site.

Author

Commented:
when i tried as attached getting error. Is the example is working fine for you.
please advise
RemoteDebug.docx
Amitkumar PSr. Consultant
CERTIFIED EXPERT

Commented:
Probably, your program is completing its execution before you launch the debugger. I will get you an example.

Author

Commented:
ok. sure
Amitkumar PSr. Consultant
CERTIFIED EXPERT

Commented:
Just remove suspend=y from the command and run it.

java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y   Test

Attaching the document for your reference.
RemoteDebugWorking.docx

Author

Commented:
My java file is as below

package com.mycompany.app;

/**
 * Hello world!
 *
 */
public class App {

    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
       
        int count = 0;
        while (true) {
              count++;
              
              if (count%1000==0) {
                System.out.println( "Count :: " + count);
              }
        }
    }

}




The folder path where App.java residing is
C:\gpprojects\sample-project\src\main\java\com\mycompany\app


I was able to compile as below

C:\gpprojects\sample-project\src\main\java\com\mycompany\app>javac App.java

C:\gpprojects\sample-project\src\main\java\com\mycompany\app>


But i was not able to run



C:\gpprojects\sample-project\src\main\java\com\mycompany\app>java App
Exception in thread "main" java.lang.NoClassDefFoundError: App (wrong name: com/
mycompany/app/App)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

C:\gpprojects\sample-project\src\main\java\com\mycompany\app>


I tried below command
java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y com.mycompany.app.App

that also did not work.

Please advise
mccarlIT Business Systems Analyst / Software Developer
CERTIFIED EXPERT
Top Expert 2015

Commented:
But i was not able to run

Do...
cd C:\gpprojects\sample-project\src\main\java

Open in new window

and then try either of the following...
java com.mycompany.app.App
java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y com.mycompany.app.App

Open in new window

Author

Commented:
i wonder why javac command worked but not java command. I do see the .class file (C:\gpprojects\sample-project\src\main\java\com\mycompany\App.class)in that path created also

Author

Commented:
It worked now as you mentioned when i ran from java folder



Count :: 403349000
Count :: 403350000
Count :: 403351000
C:\gpprojects\sample-project\src\main\java>java -Xdebug -Xrunjdwp:transport=dt_s
ocket,address=8001,server=y com.mycompany.app.App


When i try to launch remote debuggin from eclipse getting error as below as attached
Failed to connect to remote VM. Connection refused.
Connection refused: connect


How to fix it. please advise
RemoteDebug0807.docx
mccarlIT Business Systems Analyst / Software Developer
CERTIFIED EXPERT
Top Expert 2015

Commented:
Ok, so after you run the following command...

java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y com.mycompany.app.App

You should see the following message...
Listening for transport dt_socket at address: 8001

Open in new window

And the program won't be counting yet, it is just sitting there waiting for you to connect.

And then you goto Eclipse and launch the Remote Debug session using the parameters that you have shown above, and the program will start running (at least up to the first breakpoint if you have any set). But then you can do all normal debugging operations.
Amitkumar PSr. Consultant
CERTIFIED EXPERT

Commented:
Agree with mccarl.

Author

Commented:
when i ran java command on the command prompt by CDing to
C:\gpprojects\sample-project\src\main\java\com\mycompany\app
I see
Listening for transport dt_socket at address: 8001

I got above line in the command prompt.

Now on eclispe side i am having the issue

And then you goto Eclipse and launch the Remote Debug session using the parameters that you have shown above, and the program will start running

are my parameters
Host:localhost
Port:8001
are correct?
what is 8001 means. it should match with command prompt  port (ie Listening for transport dt_socket at address: 8001). For example if command prompt says
Listening for transport dt_socket at address: 8009
then i should givve in my eclipse parameters as below right

Host:localhost
Port:8009

Is that understanding is correct?
(at least up to the first breakpoint if you have any set). But then you can do all normal debugging operations.
since i have put the same program App.java (C:\Users\ganesha\kepler_workspace\junit workspace\JMock Example\src\eePackage\App.java) in eclipse when i click debug does it trigger App.java in eclipse (ie from path C:\Users\ganesha\kepler_workspace\junit workspace\JMock Example\src\eePackage\App.java) or from path C:\gpprojects\sample-project\src\main\java\com\mycompany\app\App.java (the one i used above in command prompt scenario?

Author

Commented:
what it means by error message--->failed to connect to remote VM. connection refused?

Please advise

Author

Commented:
i see

Listening for transport dt_socket at address: 8001

in my command prompt after that java command(what is meaning of those options wwith java command?
)

Now when i click debug it triggered above command prompt remote debug which is sitting and waiting.

That all make sense to me now.

My other question is i put break point at line 11 but my program never stopped counting numbers on the command prompt as attached. How do i stop the control at line 11. please advise
brkPoint.jpg

Author

Commented:
other attachmet
queueAdmin2.jpg
mccarlIT Business Systems Analyst / Software Developer
CERTIFIED EXPERT
Top Expert 2015

Commented:
My other question is i put break point at line 11 but my program never stopped counting numbers on the command prompt as attached. How do i stop the control at line 11. please advise
I can only assume that it is because you are using different code in Eclipse compared to what you are running on the command line and trying to debug. eg... on the command line you are starting "com.mycompany.app.App" from a project called "sample-project" but in Eclipse you seem to be referring to a project called "RemoteDebug" (and I can't see exactly what code is in that project). You need the exact same code for both the remote program that you are trying to debug and the Eclipse debug session that you are launching.

Author

Commented:
I see both files code same not sure where is the issue

\gpprojects\sample-project\src\main\java\com\mycompany\app code is as below


package com.mycompany.app;

/**
 * Hello world!
 *
 */
public class App {

    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
        
        int count = 0;
        while (true) {
        	count++;
        	
        	if (count%1000==0) {
                System.out.println( "Count :: " + count);
        	}
        }
    }

}



elipse APP.java is as below(C:\Users\ganesha\kepler_workspace\junit workspace\JMock Example\src\eePackage\App.java)

package eePackage;

/**
 * Hello world!
 *
 */
public class App {

    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
        
        int count = 0;
        while (true) {
        	count++;
        	
        	if (count%1000==0) {
                System.out.println( "Count :: " + count);
        	}
        }
    }

}

Open in new window

mccarlIT Business Systems Analyst / Software Developer
CERTIFIED EXPERT
Top Expert 2015

Commented:
The code that you posted above mentions "JMock Example" as the project name but in your screenshots for the Eclipse launch configuration it mentions "RemoteDebug" as the project name.

Also, even the two pieces of code that you posted above are *different*. Yes they are close but they are not EXACTLY the same. Look at the very first line of each file, the package is different.

Author

Commented:
The code that you posted above mentions "JMock Example" as the project name

File locations are different. One is inside eclipse workspace (C:\Users\ganesha\kepler_workspace\junit workspace\JMock Example\src\eePackage\App.java) other one which outside eclipse workspace(C:\\gpprojects\sample-project\src\main\java\com\mycompany\app\App.java ---> one i ran from command prompt). Are both supposed to be in the same location?.

I mean App.java i refer from command prompt and eclipse should be the same?

Please advise
mccarlIT Business Systems Analyst / Software Developer
CERTIFIED EXPERT
Top Expert 2015

Commented:
They don't necessarily need to be the exact same location (because obviously this would often be difficult when doing remote debugging for real, ie. when not just connecting to 'localhost') BUT they do need to at least be the same code. As I've been trying to tell you a couple of times now...

com.mycompany.app.App DOES NOT EQUAL eePackage.App

Yes, the class names are the same but the package is part of the fully qualified class name, and the fact that they are different makes the two classes different, even if they have the same content, they are still different.

One normal way to approach remote debugging is... you develop code in Eclipse, compile it in Eclipse, and then move the class files that are generated (and any libraries required) to your remote machine in someway (one way would be to generate a JAR file). Then you would run the code on that remote machine (like instructed above) and then have Eclipse connect to it to remotely debug it. But the point here is that it is 100% the same code that you are attempting to run as you are debugging with.

Author

Commented:
Oh that makes more sense.

How i know where my eclipse is putting App.class(generated from C:\Users\ganesha\kepler_workspace\junit workspace\JMock Example\src\eePackage\App.java )
So that i can put in some remote location and run from command prompt.

Then When i put a break point in eclipse it should stop control in the command prompt i guess right?
Please advse
IT Business Systems Analyst / Software Developer
CERTIFIED EXPERT
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Oh. I will try and let you know

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.