remote debugging in eclipse

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
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Amitkumar PSr. ConsultantCommented:
You will need to run your program outside eclipse. You can do the following:

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.

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.
0
gudii9Author 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.
0
gudii9Author Commented:
when i tried as attached getting error. Is the example is working fine for you.
please advise
RemoteDebug.docx
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Amitkumar PSr. ConsultantCommented:
Probably, your program is completing its execution before you launch the debugger. I will get you an example.
0
gudii9Author Commented:
ok. sure
0
Amitkumar PSr. ConsultantCommented:
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
0
gudii9Author 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
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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

0
gudii9Author 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
0
gudii9Author 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
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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.
0
Amitkumar PSr. ConsultantCommented:
Agree with mccarl.
0
gudii9Author 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?
0
gudii9Author Commented:
what it means by error message--->failed to connect to remote VM. connection refused?

Please advise
0
gudii9Author 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
0
gudii9Author Commented:
other attachmet
queueAdmin2.jpg
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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.
0
gudii9Author 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

0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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.
0
gudii9Author 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
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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.
0
gudii9Author 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
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
How i know where my eclipse is putting App.class
If you right-click on your Project within Eclipse, and then select "Build Path  >" and then "Configure Build Path..." to bring up the Project's Build Path properties. Then click on the "Source" tab and down the bottom it should tell you what the "Output Folder" is.

For your above example, I will guess that it will still be the default and so it should be... "C:\Users\ganesha\kepler_workspace\junit workspace\JMock Example\bin". So theoretically, if you want to test this locally (like you were doing above) before trying to do it truly remotely, you could go to a command prompt and do...
cd "C:\Users\ganesha\kepler_workspace\junit workspace\JMock Example\bin"
java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y eePackage.App

Open in new window

This will start the App exactly as it was compiled by Eclipse, in debug mode, ready to connect to it from Eclipse's remote debug option.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
Oh. I will try and let you know
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.