10

I have a executable jar with source compiled in and I want to debug it using jdb (no other debugger available in this environment unfortunately).

I am able to debug it with

jdb -classpath "${JAR_FILE}:${CLASS_PATH}" ${MAIN_CLASS} ${ARGS}

How can I get jdb to use the source that is built into the jar file?

Notes: Java 6, AIX, ksh

C. Ross
  • 31,137
  • 42
  • 147
  • 238

4 Answers4

8

If jdb is ignoring *.jar and *.zip entries for sourcepath, maybe you can whip up a batchfile to expand the source from the target jar into a temp directory and point sourcepath to that.

Something like this

MYDEBUGDIR=/temp/source/mydebug
jar -xf target.jar -C $MYDEBUGDIR
jdb -sourcepath ${MYDEBUGDIR} -classpath "${JAR_FILE}:${CLASS_PATH}" ${MAIN_CLASS} ${ARGS}
rmdir -r $MYDEBUGDIR

That way the debug source is in sync with the jar and it cleans up after itself.

Kelly S. French
  • 12,198
  • 10
  • 63
  • 93
5

It may not be possible, as stated in this (very old) post on the forums.

C. Ross
  • 31,137
  • 42
  • 147
  • 238
1

actually I managed to debug into a jar file without source code today, the steps are as follows:

  1. unzip jar file

  2. jdb -sourcepath [unzipped source folder] -classpath [the path for your main class]

  3. after jdb initializing, excute:

stop at <package>.<yourclass>:<linenunmber>
run <your main class, for example org.springframework.boot.loader.JarLauncher>
  1. after breakpoint triggered, you can step by step debug using jdb command
LIU YUE
  • 1,593
  • 11
  • 19
0

Haven't tried this personally, but perhaps the sourcepath option will allow JAR files: jdb -sourcepath ${JAR_FILE} ...

kschneid
  • 5,626
  • 23
  • 31