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
轉載于:https://www.cnblogs.com/davidwang456/p/3790550.html
總結
以上是生活随笔為你收集整理的JDK源码重新编译——支持eclipse调试JDK源码--转载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Reactor构架模式--转载
- 下一篇: 如何使用JCA (J2EE 连接器架构)