博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JDK源码重新编译——支持eclipse调试JDK源码--转载
阅读量:2235 次
发布时间:2019-05-09

本文共 2914 字,大约阅读时间需要 9 分钟。

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

你可能感兴趣的文章
幂等性验证思想
查看>>
DB理论--数据存储方式
查看>>
PB协议的说明与使用
查看>>
什么是TPS,什么是QPS,区别是什么?
查看>>
git pull遇到错误:error: Your local changes to the following files would be overwritten by merge:
查看>>
arraylist扩容时机java8
查看>>
logback中additivity的理解
查看>>
一篇文章搞懂hash,hashcode,equals,==的用法
查看>>
mysql数据库,悲观锁。for update 的用法。
查看>>
springboot+jta+atomikos多数据源和 springboot+mybatisplus+aop实现数据库读写分离而引发的一些思考
查看>>
java面试中常考的一些面试sql语句
查看>>
一个字节等于多少位?
查看>>
帧框架frameset的用法总结
查看>>
java1.8中创建hashmap的初始化大小设置标准
查看>>
mark一下,service的实现层没有加@service注解。
查看>>
jq对象转换成js对象。已经jq的复合选择器。
查看>>
(一)alin‘s mysql学习笔记----概述
查看>>
(二)alin’s mysql学习笔记----mysql的存储引擎
查看>>
(三)alin’s mysql学习笔记----常用的join连接查询
查看>>
(四)alin’s mysql学习笔记----索引简介
查看>>