gudii9
asked on
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
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
when i tried as attached getting error. Is the example is working fine for you.
please advise
RemoteDebug.docx
please advise
RemoteDebug.docx
Probably, your program is completing its execution before you launch the debugger. I will get you an example.
ASKER
ok. sure
Just remove suspend=y from the command and run it.
Attaching the document for your reference.
RemoteDebugWorking.docx
java -Xdebug -Xrunjdwp:transport=dt_socket,addres s=8001,ser ver=y Test
Attaching the document for your reference.
RemoteDebugWorking.docx
ASKER
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-proje ct\src\mai n\java\com \mycompany \app
I was able to compile as below
C:\gpprojects\sample-proje ct\src\mai n\java\com \mycompany \app>javac App.java
C:\gpprojects\sample-proje ct\src\mai n\java\com \mycompany \app>
But i was not able to run
C:\gpprojects\sample-proje ct\src\mai n\java\com \mycompany \app>java App
Exception in thread "main" java.lang.NoClassDefFoundE rror: App (wrong name: com/
mycompany/app/App)
at java.lang.ClassLoader.defi neClass1(N ative Method)
at java.lang.ClassLoader.defi neClass(Un known Source)
at java.security.SecureClassL oader.defi neClass(Un known Source)
at java.net.URLClassLoader.de fineClass( Unknown Source)
at java.net.URLClassLoader.ac cess$100(U nknown Source)
at java.net.URLClassLoader$1. run(Unknow n Source)
at java.net.URLClassLoader$1. run(Unknow n Source)
at java.security.AccessContro ller.doPri vileged(Na tive Method)
at java.net.URLClassLoader.fi ndClass(Un known Source)
at java.lang.ClassLoader.load Class(Unkn own Source)
at sun.misc.Launcher$AppClass Loader.loa dClass(Unk nown Source)
at java.lang.ClassLoader.load Class(Unkn own Source)
at sun.launcher.LauncherHelpe r.checkAnd LoadMain(U nknown Source)
C:\gpprojects\sample-proje ct\src\mai n\java\com \mycompany \app>
I tried below command
java -Xdebug -Xrunjdwp:transport=dt_soc ket,addres s=8001,ser ver=y com.mycompany.app.App
that also did not work.
Please advise
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-proje
I was able to compile as below
C:\gpprojects\sample-proje
C:\gpprojects\sample-proje
But i was not able to run
C:\gpprojects\sample-proje
Exception in thread "main" java.lang.NoClassDefFoundE
mycompany/app/App)
at java.lang.ClassLoader.defi
at java.lang.ClassLoader.defi
at java.security.SecureClassL
at java.net.URLClassLoader.de
at java.net.URLClassLoader.ac
at java.net.URLClassLoader$1.
at java.net.URLClassLoader$1.
at java.security.AccessContro
at java.net.URLClassLoader.fi
at java.lang.ClassLoader.load
at sun.misc.Launcher$AppClass
at java.lang.ClassLoader.load
at sun.launcher.LauncherHelpe
C:\gpprojects\sample-proje
I tried below command
java -Xdebug -Xrunjdwp:transport=dt_soc
that also did not work.
Please advise
But i was not able to run
Do...
cd C:\gpprojects\sample-project\src\main\java
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
ASKER
i wonder why javac command worked but not java command. I do see the .class file (C:\gpprojects\sample-proj ect\src\ma in\java\co m\mycompan y\App.clas s)in that path created also
ASKER
It worked now as you mentioned when i ran from java folder
Count :: 403349000
Count :: 403350000
Count :: 403351000
C:\gpprojects\sample-proje ct\src\mai n\java>jav a -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
Count :: 403349000
Count :: 403350000
Count :: 403351000
C:\gpprojects\sample-proje
ocket,address=8001,server=
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
Ok, so after you run the following command...
java -Xdebug -Xrunjdwp:transport=dt_soc ket,addres s=8001,ser ver=y com.mycompany.app.App
You should see the following message...
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.
java -Xdebug -Xrunjdwp:transport=dt_soc
You should see the following message...
Listening for transport dt_socket at address: 8001
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.
Agree with mccarl.
ASKER
when i ran java command on the command prompt by CDing to
C:\gpprojects\sample-proje ct\src\mai n\java\com \mycompany \app
I see
I got above line in the command prompt.
Now on eclispe side i am having the issue
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?
orkspace\j unit 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_wo rkspace\ju nit workspace\JMock Example\src\eePackage\App. java) or from path C:\gpprojects\sample-proje ct\src\mai n\java\com \mycompany \app\App.j ava (the one i used above in command prompt scenario?
C:\gpprojects\sample-proje
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_w
ASKER
what it means by error message--->failed to connect to remote VM. connection refused?
Please advise
Please advise
ASKER
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
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
ASKER
other attachmet
queueAdmin2.jpg
queueAdmin2.jpg
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 adviseI 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.
ASKER
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);
}
}
}
}
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.
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.
ASKER
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_w
I mean App.java i refer from command prompt and eclipse should be the same?
Please advise
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.
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.
ASKER
Oh that makes more sense.
How i know where my eclipse is putting App.class(generated from C:\Users\ganesha\kepler_wo rkspace\ju nit 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
How i know where my eclipse is putting App.class(generated from C:\Users\ganesha\kepler_wo
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh. I will try and let you know
ASKER
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