JDK source code recompile--Support Eclipse debugging JDK source code--Reprint

Source: Internet
Author: User

Recently in the research JDK source code, found that debug can not view the value of the variable in the source code. Since the JDK provided by Sun does not look at the running local variables, it needs to recompile the Rt.jar.

The following six steps are a concrete step to compiling the 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 was absolutely critical when trying to build the source distribution of JDK 6.

Step 4:extract Rt.jar

Extract the original Rt.jar file, that's 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 to the folder where the Rt.jar file was expanded.  This ensures the final set have 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.

If you want to track debugging in Eclipse, you need to select the installed JDK under the java-installed JRE, Windows-Preferences, click Edit, and then in the JRE system listed In the Libraries list, select Rt.jar, and set the source attachment to C:\java\jdk1.6.0_07\src.zip.

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

Here is a convenient Linux script, as long as the set of Java_home, you can easily fix the above things:)

#!/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

Original: HTTP://HI.BAIDU.COM/AUSTINCAO/ITEM/E6E91329892497C1A4275A1A

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.