JDK源码重新编译——支持eclipse调试JDK源码--转载

最近在研究jdk源码,发现debug时无法查看源码里的变量值。 因为sun提供的jdk并不能查看运行中的局部变量,需要重新编译一下rt.jar。

下面这六步是编译jdk的具体步骤:

 

Step 1:  Locate the JDK source

First navigate to the JDK install directory, and locate the src.zip file. This file contains the JDK sources – and is absolutely invaluable for the rest of this process.

Next, unzip this folder to some location, such as c:\src.

 

Step 2: List all the source files to be compiled

Generate a list of all .java files in the unzipped folder, out to a separate file:
dir /B /S /X c:\src\*.java > jdk-src.txt

 

Step 3: Compile the source

Compile the source files named in this file, using the –g option.

javac-verbose -nowarn -g -source 1.6 -target 1.6 -J-Xms512m -J-Xmx1024m -bootclasspath C:\java\jdk1.6.0_07\jre\lib\rt.jar;C:\java\jdk1.6.0_07\jre\lib\jce.jar;C:\java\jdk1.6.0_07\jre\lib\jsse.jar;C:\java\jdk1.6.0_07\jre\lib\resources.jar;C:\java\jdk1.6.0_07\jre\lib\charsets.jar;C:\java\jdk1.6.0_07\jre\lib\deploy.jar -sourcepath src -classpath src -d jdk-class @jdk-src.txt

 Note the presence of the –bootclasspath flag which makes the stated JARs available to the compiler. This is absolutely critical when trying to build the source distribution of JDK 6.

 

Step 4: Extract rt.jar

Extract the original rt.jar file, that is found in JAVA_HOME\jre\lib, into a temporary folder.

 

Step 5:  Generate a composite build

Copy the newly compiled .class files from our jdk-class over the folder where the rt.jar file was expanded. This ensures that the final set has old classes overwritten by newer classes with debug information, while still retaining class files that we couldn't compile.

 

Step 6: Regenerate rt.jar

Finally, recompress all the files from the composite folder into a new rt.jar file, and overwrite the original rt.jar file with this new one.

 

如果想在eclipse中跟踪调试,需要在Windows -> Preferences -> Java-Installed JRE下,选择安装的jdk,点edit,然后在列出的jre system libraries列表中选择rt.jar,设置其中的Source attachment为C:\java\jdk1.6.0_07\src.zip。

 

------------------------------------------------------------------------------------------------------

下面是一个方便的linux脚本, 只要设置了JAVA_HOME, 就可以轻松搞定上面的事情了:)

#!/bin/sh

if [ -z "$JAVA_HOME" ]

then

echo "Must set JAVA_HOME"

exit 1

fi

cd $JAVA_HOME

mkdir temp

cp src.zip temp/

cd temp/

mkdir out

unzip src.zip

rm src.zip

find . -name *.java > filelist

echo "$(wc -l filelist) java files to compile"

javac  -g -d out/ -J-Xmx1024m -cp "../jre/lib/tools.jar:../jre/lib/rt.jar" @filelist 

if [ $? != 0 ]

then

echo "compile error!"

exit 1

fi

unzip $JAVA_HOME/jre/lib/rt.jar -d $JAVA_HOME/temp/old_classes

cp -r  $JAVA_HOME/temp/out/* $JAVA_HOME/temp/old_classes/

cd $JAVA_HOME/temp/old_classes/

jar cf rt_debug.jar *

cp rt_debug.jar $JAVA_HOME/jre/lib/

mv $JAVA_HOME/jre/lib/rt.jar $JAVA_HOME/lib/rt_old.jar

cd $JAVA_HOME/jre/lib/

ln -s rt_debug.jar rt.jar

rm -rf $JAVA_HOME/temp

原文:http://hi.baidu.com/austincao/item/e6e91329892497c1a4275a1a

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值