Setup eclipse can debug the JDK source code in debug mode and display the value of the local variable

Source: Internet
Author: User
Tags save file

Recently suddenly germination of the idea of research JDK source code, so I think in their usual eclipse can debug JDK source code.

The entire setup process is also simple:

First of all you have to install the JDK (my JDK installation path root directory is D:\Java\jdk-8u92-windows-x64), JDK installation path has a "src.zip" is the JDK source file compression package;

Set the Java_home variable and path variable for the environment variable (java_home variable value is also D:\Java\jdk-8u92-windows-x64).

Then turn on Eclipse settings to debug the JDK source code in debug mode:

1 Open the menu bar for Eclipse Windows-Preferences: Point open Java-installed JREs, click Add StandardVM,JRE home fills in the %java_home% path in your environment variable (my%java_home% is D:\Java\ Jdk-8u92-windows-x64);

2 in JRE system libraries, you can see the relevant jar packages for the JDK source code, and open a jar (such as D:\Java\jdk-8u92-windows-x64\jre\lib\Resources.jar, D : \java\jdk-8u92-windows-x64\jre\lib\Rt.jar... ), you can see "source attachment: (None)", click on the right of "source attachment ..." Select external Location->path through the path to the JDK source file compression package %java_ home%\src.zip;

With the above two-step setup, there is a JRE that can debug the JDK source code.

You can debug the JDK source by simply specifying the JRE of the project as the set-up JRE.

Through the above settings, although debugging can enter the JDK source code, but you will find the JDK source method of the parameters and methods in the body of the local variables are unable to display the value.

That's because the JRE jar package is designed to save file size, and Oracle removes the display of variable values when compiling and hitting a jar package.

So, we need to recompile and hit the jar package:

1 Find an empty folder as the workspace root directory, such as E:\jdk, create a new two folder "jdk_src" and "jdk_debug" inside, where "jdk_src" Used to store the. Java source files to be compiled, "jdk_debug" is used to store compiled. class bytecode files;

2 to %java_home%\jre\lib find rt.jar, copy it to work space E:\jdk;

3 Open the JDK source file compression package %java_home%\src.zip, the JAVA,javax,org these three folders, Drag-and-drop the E:\jdk\jdk_src folder that is used to store the. Java source files that you want to compile.

4 run cmd, execute the following command:

4.1 Switch the directory to the workspace CD E:\jdk; lists the E:\jdk\jdk_src to be compiled. Java source files to filelist.txt:dir/b/s/x. \jdk_src\*. java >. \filelist.txt; After completion, a filelist.txt will be generated in E:\JDK, which lists many lines **.java;

4.2 The. Java source files that are to be compiled in the jdk_src are compiled into a. Class bytecode file, which is placed in the folder of Jdk_debug , which is used to store the compiled. Class bytecode file:Javac- J-xms16m-j-xmx1024m-sourcepath. \jdk_src-cp. \rt.jar-d. \jdk_debug-g @.\filelist.txt >> \log.txt 2>&1 ; During compilation, the compilation log file Log.txt will be generated in E:\jdk\ and the corresponding folder and. Class bytecode files can be seen in E:\jdk\jdk_debug after compilation.

4.3 Switch the directory CD E:\jdk\jdk_debug, the. Class bytecode file into a jar package:jar cf0. \rt_debug.jar. \*; When the package is complete, it will be in E:\jdk\jdk_ Debug generates Rt_debug.jar.

Chinese references: http://blog.csdn.net/appleprince88/article/details/21873807

English references: Http://stackoverflow.com/questions/18255474/debug-jdk-source-cant-watch-variable-what-it-is

Setup eclipse can debug the JDK source code in debug mode and display the value of the local variable

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.