最近在研究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

 

jdk源码调试功能的更多相关文章

  1. JDK源码调试

    1.首先遇到了一个问题line unavailable,然后通过以下方式解决: http://blog.csdn.net/xuefeng0707/article/details/8738869 对于想 ...

  2. eclipse中jdk源码调试步骤

    分析源码是学习一项技术内幕最有效的手段.由于正常的引入JAr包源码没法进行对源码打断点,想要深入了解源码不方便.下面就开始介绍源码调试的步骤. 1.在eclipse新建一个JAVA项目compare_ ...

  3. jdk源码调试进去形参没有值

    https://blog.csdn.net/u010407050/article/details/76690478 1.在你的D:盘新建jdk文件夹,然后在文件夹里面分别创建两个文件夹jdk_src( ...

  4. JDK源码调试常见错误。

    1.删除不需要的代码,即swing相关的代码 2.执行命令时要将前提环境进入文件夹如下: 起初没有完全执行第一条,因为网上说可以根据需要选择相关的代码,于是就没有删除,以后第一次模仿网上的例子的时候要 ...

  5. 震惊!我竟然发现了JDK源码的问题

    读源码时的思考 最近在看concurrent包下线程池的源码,当我看到ThreadPoolExecutor类的时候,发现了JDK源码的一个问题.以下是ThreadPoolExecutor类的addWo ...

  6. 跟踪调试JDK源码时遇到的问题及解决方法

    目录 问题描述 解决思路 在IntelliJ IDEA中调试JDK源码 在eclipse中调试JDK源码 总结 问题描述 最近在研究MyBatis的缓存机制,需要回顾一下HashMap的实现原理.于是 ...

  7. eclipse调试jdk源码

    摘要 介绍使用eclipse调试jdk源码 java是一门开源的程序设计语言,喜欢研究源码的java开发者总会忍不住debug一下jdk源码.虽然官方的jdk自带了源码包src.zip,然而在debu ...

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

    最近在研究jdk源码,发现debug时无法查看源码里的变量值. 因为sun提供的jdk并不能查看运行中的局部变量,需要重新编译一下rt.jar. 下面这六步是编译jdk的具体步骤: Step 1:   ...

  9. eclipse如何debug调试jdk源码(任何源码)并显示局部变量

    最近要看struts2源码 仿照了一下查看jdk源码的方式 首先你要有strtus2的jar包和源码,在struts官网上下载时,选择full版本,里面会有src也就是源码了. jar导入项目,保证可 ...

随机推荐

  1. 1063: [Noi2008]道路设计 - BZOJ

    Description Z 国坐落于遥远而又神奇的东方半岛上,在小Z 的统治时代公路成为这里主要的交通手段.Z 国共有n 座城市,一些城市之间由双向的公路所连接.非常神奇的是Z 国的每个城市所处的经度 ...

  2. bzoj 2876: [Noi2012]骑行川藏 拉格朗日数乘

    2876: [Noi2012]骑行川藏 Time Limit: 20 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 1033  Solved: ...

  3. pythn BeautifulSoup

    http://rsj217.diandian.com/post/2012-11-01/40041235132 Beautiful Soup 是用 Python 写的一个 HTML/XML 的解析器,它 ...

  4. hdu 4652 Dice 概率DP

    思路: dp[i]表示当前在已经投掷出i个不相同/相同这个状态时期望还需要投掷多少次 对于第一种情况有: dp[0] = 1+dp[1] dp[1] = 1+((m-1)*dp[1]+dp[2])/m ...

  5. SQL四种语言:DDL,DML,DCL,TCL

    1.DDL(Data Definition Language)数据库定义语言statements are used to define the database structure or schema ...

  6. easyui源码翻译1.32--datagrid(数据表格)

    前言 此前网上有easyui1.25的源码  应该算是比较老的版本  之后又经历了1.26 . 1.3. 1.31. 1.32 .1.33.1.34  1.33开始支持css3 算是又一个转折  但是 ...

  7. Vue.js vui 饿了么Vue2.0的组件库

    http://www.oschina.net/news/78038/vue-js-2-0-3 http://git.oschina.net/durcframework/vui http://eleme ...

  8. Node.js学习(11)----HTTP服务器与客户端

    Node.js 标准库提供了 http 模块,其中封装了一个高效的 HTTP 服务器和一个简易的HTTP 客户端.http.Server 是一个基于事件的 HTTP 服务器,它的核心由 Node.js ...

  9. 1067. Disk Tree(字符串)

    1067 破题啊  写完发现理解错题意了 子目录下会有跟之前重名的 把输入的字符串存下来 排下序 然后依次找跟上面有没有重的 #include <iostream> #include< ...

  10. JSON 之JAVA 解析

    一.   JSON (JavaScript Object Notation)一种简单的数据格式,比xml更轻巧. Json建构于两种结构:     1.“名称/值”对的集合(A collection ...