Reputation: 32755
For a class exercise on game trees, I have to write code that works with a .jar file. I haven't used Java in this way before. My Eclipse project tree looks like this:
To run the code, I was told to do this on the command line:
java -jar VierOpEenRij.jar Mens spel.speler.Random 5 5
How do I debug this code? I have tried tinkering with Eclipse's debug configurations and I also tried executing jdb -jar VierOpEenRij.jar Mens spel.speler.Random 5 5
but I can't figure out a way to start the debugger.
How do I debug my code when a .jar file contains the main method?
Upvotes: 2
Views: 3133
Reputation: 312
You need to specify classpath in jdb.
jdb -classpath [jar-file] [main-class-full-name] [args]
In your case the jar file will be: VierOpEenRij.jar
Main class name you could find in jar archive in META-INF/MANIFEST.MF.
Upvotes: 0
Reputation: 22663
I might be completely off as I haven't really been in this situation, but wouldn't right-click on the jar -> debug as ... -> Java application do the trick?
EDIT:
Managed to make it work this way:
For some reason I would expect to be able to right-click the jar and do directly dbug as java app though... the main is indicated in the manifest, but it doesn't seem to find it. Don't know why. But in the meantime, that works.
EDIT2: Actually, now I can directly right-click the jar (or even the project) and select the right main when a dialog pops up, and it's all good. Maybe I missed something earlier. Any way, you're good to go.)
In the picture below, MainInJar.main() calls ClassOutOfJar.somethingOutOfJar(), which prints something to the screen.
Upvotes: 1
Reputation: 2425
I'm not sure about debugging with jdb
, but if you're debugging in Eclipse, it won't matter what the final packaging(e.g. jar) is. If you set up the debugging for the Random (class with the main method?) class then you will be debugging your program just fine.
Upvotes: 2