I'm a programmer with strong C++ background, but new to Java world. Now I have a question about debugging.
How to debug a pre-compiled Java .class file using Eclipse IDE? And I find it is really not an easy task to find the answer by Googling.
In order for my question to be really precise and no misleading, I expound it as follows.
I have two .java source files below:
$
├── src
│ └── mypkg1
│ └── Timeline.java
└── test
└── mypkg1
└── TimelineTest.java
In the root folder($), I can compile and run TimelineTest.java using two commands:
javac -classpath ./src test/mypkg1/TimelineTest.java
java -classpath ./src:./test mypkg1.TimelineTest
Now I have $/test/mypkg1/TimelineTest.class with Java byte code in it.
Then how can I do source-level debugging on the TimelineTest.class?
I tried, but no success yet. I created a Eclipse project as $/test/mypkg1/.project, then create a Debug configuration for it as below. But, when start debugging, I got red error message:
Error: Could not find or load main class TimelineTest
Caused by: java.lang.NoClassDefFoundError: mypkg1/TimelineTest (wrong name: TimelineTest)
Then what's the correct way to do it?
The key requirement here is, I should not be bothered to do verbose Eclipse project settings, mouse clicking here and there hundreds of times. What I want is quick loading the binary and start debugging. You know, it is definitely true in C++ world. For example, using Visual Studio IDE, File → Open Project → Select an EXE file as project-file, that is the way you tell VS IDE to debug that EXE. After the "project" is opened, press F10, the debugger stops the debuggee at first line of main(), just that simple.
How can I achieve the same with Eclipse? Or, some other feasible Java debugger recommended?
== Timeline.java ==
package mypkg1;
public class Timeline {
private int fetchCount;
public void setFetchCount(int fetchCount) {
this.fetchCount = fetchCount;
}
public int getFetchCount() {
return fetchCount;
}
}
== TimelineTest.java ==
package mypkg1;
public class TimelineTest {
public static void main(String[] args) {
Timeline timeline = new Timeline();
int expected = 5;
timeline.setFetchCount(expected);
int actual = timeline.getFetchCount();
System.out.println("Fetch = "+actual);
}
}

