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
JDK源码重新编译——支持eclipse调试JDK源码--转载的更多相关文章
- eclipse调试jdk源码
摘要 介绍使用eclipse调试jdk源码 java是一门开源的程序设计语言,喜欢研究源码的java开发者总会忍不住debug一下jdk源码.虽然官方的jdk自带了源码包src.zip,然而在debu ...
- 利用eclipse调试JDK源码
先看效果图 综合网上各种教程,总结如下 新建 D:/jdk/src .D:/jdk/debug 目录 src存放源码 debug存放编译结果 将 %JAVA_HOME%/src.zip 解压到 D:/ ...
- 修改,编译,GDB调试openjdk8源码(docker环境下)
在上一章<在docker上编译openjdk8>里,我们在docker容器内成功编译了openjdk8的源码,有没有读者朋友产生过这个念头:"能不能修改openjdk源码,构建一 ...
- 框架源码系列五:学习源码的方法(学习源码的目的、 学习源码的方法、Eclipse里面查看源码的常用快捷键和方法)
一. 学习源码的目的 1. 为了扩展和调优:掌握框架的工作流程和原理 2. 为了提升自己的编程技能:学习他人的设计思想.编程技巧 二. 学习源码的方法 方法一: 1)掌握研究的对象和研究对象的核心概念 ...
- Git下载Spring项目源码并编译为Eclipse
1)当前系统中安装了gradle,如果为安装,可以从:http://www.gradle.org/downloads,,下载完后进行解压到任意盘符,然后增加环境变量GRADLE_HOME,并在环境变量 ...
- 跟踪调试JDK源码时遇到的问题及解决方法
目录 问题描述 解决思路 在IntelliJ IDEA中调试JDK源码 在eclipse中调试JDK源码 总结 问题描述 最近在研究MyBatis的缓存机制,需要回顾一下HashMap的实现原理.于是 ...
- Solr4.8.0源码分析(4)之Eclipse Solr调试环境搭建
Solr4.8.0源码分析(4)之Eclipse Solr调试环境搭建 由于公司里的Solr调试都是用远程jpda进行的,但是家里只有一台电脑所以不能jpda进行调试,这是因为jpda的端口冲突.所以 ...
- Apache Flume 1.7.0 源码编译 导入Eclipse
前言 最近看了看Apache Flume,在虚拟机里跑了一下flume + kafka + storm + mysql架构的demo,功能很简单,主要是用flume收集数据源(http上报信息),放入 ...
- Android动态方式破解apk进阶篇(IDA调试so源码)
一.前言 今天我们继续来看破解apk的相关知识,在前一篇:Eclipse动态调试smali源码破解apk 我们今天主要来看如何使用IDA来调试Android中的native源码,因为现在一些app,为 ...
随机推荐
- PHPCMS 核心代码与 www 分离部署
为了满足更多用户二次开发的兴趣与爱好,同时,为了更加安全.可以通过修改入口代码的包含方式来让主程序和www程序分开. 先看下面目录结构: (图1) 我们需要将 phpcms 目录和 index.php ...
- poj 3250 Bad Hair Day 单调栈入门
Bad Hair Day 题意:给n(n <= 800,000)头牛,每头牛都有一个高度h,每头牛都只能看到右边比它矮的牛的头发,将每头牛看到的牛的头发加起来为多少? 思路:每头要进栈的牛,将栈 ...
- 【方言】Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 几种 方言配置差异 <?xml v ...
- 我的PHP之旅--SQL语句
SQL语句 结构化查询语言(Structured Query Language)简称SQL,是一种操作数据的语言. 增加记录 INSERT INTO table_name(字段1, 字段2, 字段3) ...
- Codeforces Round #208 (Div. 2)
A - Dima and Continuous Line 水题:直接模拟: #include<cstdio> #define maxn 1005 using namespace std; ...
- HTML5给我们带来了什么?
HTML5初探 传说中的HTML标准已经超过10年没有更新了,如今HTML5席卷全球,那么到底什么是HTML5呢?都在讲HTML5是web的新一代标准,它有着很多之前浏览器没有的新特性,可以说HTML ...
- Maven如何手动添加jar包到本地Maven仓库
Apache Maven,是一个软件(特别是Java软件)项目管理及自动构建工具,由Apache软件基金会所提供.基于项目对象模型(缩写:POM)概念,Maven利用一个中央信息片断能管理一个项目的构 ...
- easyui源码翻译1.32--panel(面板)
前言 昨天发布了表格datagrid的翻译源码 ,easyui的许多插件有依赖关系 比如datagrid 的渲染需要panel.resizable.linkbutton.pagination 今 ...
- [topcoder]FoxAndChess
http://community.topcoder.com/stat?c=problem_statement&pm=12725&rd=15702 这题比较简单.首先所有的LR的顺序要一 ...
- RTMP
实时消息传输协议 RTMP(Real Time Messaging Protocol) http://blog.csdn.net/defonds/article/details/17403225 译序 ...