您的位置:首页 > 编程语言 > Java开发

How to debug code from rt.jar with JDK 1.4.1?

2005-04-15 10:17 495 查看
blocnjbb.oA: If you want to debug code from rt.jar you will get some information like "can't debug - absent line information."
This small howto will tell you how.
Create your own rt.jar (myrt.jar)
— create a directory (newruntime) with a src directory
— unzip the jdk source into the src directory
— create a new java project with the project contents directory newruntime
— let it compile - takes a while
— export as a jar file Create a new JRE configuration
— Prefrences >> Java >> Installed JREs >> Add
— Browse to the usual JRE home directory
— uncheck "use default system libraries"
— add myrt.jar as an external jar above rt.jar Verify

While debuging check the command line ("Properties" page of the process
in the debug perspective) to make sure that myrt.jar is on the boot
classpath
— if not add myrt.jar to the bootclasspath on the
commmandline in your run configurations: -Xbootclasspath/p:C:dir omy
ewruntimemyrt.jar .
And another answer:
For the interested here a step-by-step explanation with script:
(1) The bottom line is:
* get the JDK source (i did it with version 1.4.1)
* get the original rt.jar for the same version
* unzip the rt.jar into a directory OriginalRT
* unzip the JDK source into a directory RTSource

(2) Now the fun starts:
* delete all files from RTSource that are NOT contained in OriginalRT
(apparently old classes, they do not compile ...)
* compile the rest of the java files in RTSource with the "generate debug
information" flag (and the RTSource directory, dt.jar, tools.jar and
htmlconverter.jar in the classpath)
* copy all compiled classes that are in OriginalRT but not in RTSource into
the corresponding place in RTSource
* jar RTSource into a file rt_debug.jar
* use rt_debug.jar instead of rt.jar in your classpath -> et voila!

I found a cygwin script on the web doing all the things described in (2),
here it is in case you want to use it (thanks to the original creator of the
script!):

#!/bin/sh

# Change these four paths = as required

# Base dir
J***A_HOME=/cygdrive/c/j2sdk1.4.1

# Where src.zip was extracted
J***A_SOURCE=/cygdrive/c/JavaSourceCompile/RTSource

# Where rt.jar was extracted
RT_CLASSES=/cygdrive/c/JavaSourceCompile/OriginalRT

# Where to put the compiled classes
OUT_DIR=/cygdrive/c/JavaSourceCompile/RTSource

# These are the required options for javac, do not change
OPTIONS="-g -nowarn -sourcepath . -d `cygpath -wp $OUT_DIR` -source
1.4 -target 1.4"
SEP=";"

CLASSPATH=$J***A_HOME/lib/dt.jar$SEP$J***A_HOME/lib/tools.jar$SEP$J***A_HOME/li
b/htmlconverter.jar
J***AC_HOME=$J***A_HOME/bin

# Loop through each java file in the source dir
cd $J***A_SOURCE

#${J***AC_HOME}/javac -classpath `cygpath -wp $CLASSPATH` $OPTIONS
`cygpath -wp ./com/sun/corba/se/ActivationIDL/ActivatorHelper.java`

#/usr/bin/find -name "*.java" | while read J***A;
#do
# echo $J***A

# Is this file part of rt.jar, or is it an obsolete source file
# eg = com/sun/corba/se/internal/Interceptors/ThreadCurrentStack.java

# CLASS=`echo $J***A | sed "s/.java/.class/g"`
# echo ${RT_CLASSES}/${CLASS}
# if [ -e ${RT_CLASSES}/${CLASS} ];
# then
# # Has this file already been compiled
# if [ -e ${OUT_DIR}/${CLASS} ];
# then
# echo Already compiled.
# else
# ${J***AC_HOME}/javac -classpath `cygpath -wp $CLASSPATH` $OPTIONS
`cygpath -wp $J***A`
# fi
# else
# echo Obsolete source file.
# fi
#done

# Now check for any files that are in rt.jar but not src.zip
cd $RT_CLASSES
/usr/bin/find . -type f | while read CLASS;

do
if [ ! -f ${OUT_DIR}/${CLASS} ]; then
echo Not found : $CLASS
# Uncomment this once the script has been run and all classes have
successfully compiled
# cp --parents $CLASS $OUT_DIR
fi
done

That runs for a while, because it's quite some amount of classes - but it
works!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: