Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying sourcepath in jdb, what am I doing wrong?

Tags:

java

jdb

I have a java project in which the file system is as follows: I have 3 directories: bin, src, and lib.

  • src contains my *.java files
  • bin contains my *.class files (compiled using the files in src)
  • lib contains a few *.jar files imported by most of the src files

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?

like image 809
brnby Avatar asked Nov 16 '13 13:11

brnby


1 Answers

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]
like image 83
Oo.oO Avatar answered Sep 22 '22 21:09

Oo.oO