Dreamk33
Dreamk33

Reputation: 247

Debugging in java with jdb : "Error: impossible to find or load the main class"

it's my first project in java and I'd like to us jdb as a debugging tool, but I'm having some issues. Could you help me please?

The file with the "main" function is "Frame.java". I have also lots of other .java files in the same repertory, and they are all part of the same package.

To compile I use :

javac -d classes/ -cp classes/ *.java

So my .class files are in the directory classes/packagename/

To execute the programme I use :

java -cp classes/ packagename.Frame

I am not sure if it is the best way to do it, but it's been working for everything I wanted to do as of now.

To debug, here is the output of two of the many commands I tried :

$ jdb Frame
Initializing jdb ...
> stop in Frame.main
Deferring breakpoint Frame.main.
It will be set after the class is loaded.
> run
run Frame
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
> 
VM Started: Erreur : impossible de trouver ou charger la classe principale Frame

The application exited

and the second one:

$ jdb -launch Frame
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
> 
VM Started: No frames on the current call stack

main[1] next
> Erreur : impossible de trouver ou charger la classe principale Frame

The application exited

The error message means "Error: impossible to find or load the main class Frame".

What did I do wrong?

Thank you in advance.

Upvotes: 4

Views: 1702

Answers (1)

Shubhangi
Shubhangi

Reputation: 2264

You need to provide classpath to jdb as well. Below command works.

jdb -classpath classes1 packagename.mainclass

$ jdb -classpath  classes1 packagename.mainclass
Initializing jdb ...
> run
run packagename.mainclass
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Hello//...........

The application exited

Upvotes: 3

Related Questions