Use a jar with source as source for jdb?

C. Ross picture C. Ross · Sep 8, 2010 · Viewed 10.4k times · Source

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

Answer

Kelly S. French picture Kelly S. French · Nov 12, 2010

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.