I have a java project in which the file system is as follows:
I have 3 directories: bin, src, and lib.
I am learning how to use jdb but every time I try and use the list command it just says that the source file cannot be found. I am running the following command from within my bin directory:
jdb -classpath ../lib/*:. -sourcepath ../src envelope.Envelope
where my main method is contained within the Envelope class which is part of the envelope package, what am I doing wrong?
I know that this one is very old, but maybe someone will be still interested in it
Let's say we have file
package mypackage;
public class Main {
public static void main(String [] arg) {
System.out.println("Hello world");
}
}
and layout of the project follows
jdb_test/
├── src
│ └── mypackage
│ └── Main.java
└── target
└── mypackage
└── Main.class
class file was compiled using:
javac -sourcepath src -d target src/mypackage/Main.java
# if you have multiple files, you can always do
find . -name "*.java" -exec javac -sourcepath src -d target {} \;
Then, being inside jdb_test directory, we can call
jdb -sourcepath src -classpath target mypackage.Main
and debug the code
Initializing jdb ...
> stop in mypackage.Main.main
Deferring breakpoint mypackage.Main.main.
It will be set after the class is loaded.
> run
run mypackage.Main
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Set deferred breakpoint mypackage.Main.main
Breakpoint hit: "thread=main", mypackage.Main.main(), line=5 bci=0
5 System.out.println("Hello world");
main[1] list
1 package mypackage;
2
3 public class Main {
4 public static void main(String [] arg) {
5 => System.out.println("Hello world");
6 }
7 }
main[1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With