IDEA build the JDK source code reading environment and the problems encountered


background

View JDK source code directly in the project, it can not add a comment, you need to build local

Construct

Before building a blog post with a pure way of JDK source code is successful (https://blog.csdn.net/qq_42191317/article/details/102772497), but go after compiling error (missing package), and a series of problem, so a final decision from the git clone a building directly over the others. We will practice before the final attached.

I'm from the direct https://github.com/wupeixuan/JDKSourceCode1.8 here clone directly open to local use, but still have problems (when reading the source code, click into the method associated with the jdk source on the source code itself) ,please look below

If they build what will happen?
The first thing I encounter is:

  • Lack com.sun.tools package
  • Lack sun.awt.UNIXToolkit and sun.font.FontConfigManager two classes lead to project an error

The two, the first good, second from the Internet to find these files manually into their own class corresponding to the item, I found a long time to find, or error, real people wear, so I gave up building their own .

Lack com.sun.tools package

Here Insert Picture Description
Solutions: File => Project structure => Libraries lib packages under the jdk path added to the project, as shown below:
Here Insert Picture Description

Lack sun.awt.UNIXToolkit and sun.font.FontConfigManager two classes lead to project an error

Solution: manually add these two classes in the src directory
Here Insert Picture Description

Reading the source code in the method associated with the click into the source code itself on jdk source

Here Insert Picture Description
I can see the look of AQS is a class method file is readonly, then click directly into the jdk discover the source code, but not my own building, and this is the way I built my own JDK source Click to go
Here Insert Picture Description
this too Difficult

Reference blog also gives the answer, but did not write complete.
Solution: exclude src.zip file, you can operate the following figure.
Here Insert Picture Description
First statement in accordance with the landlord to do so is right, we verify
Here Insert Picture Description
my direct wholly deleted, and then add the JDK directory SRC my own built
Here Insert Picture Description
above, after completing the operation, in accordance with the prior AQS click into this category, or enter the JDK found the source code itself, I despair, did not find a good solution.

It took a very long time. . . . . . .
Gas I hit the keyboard, then hit the keyboard found in this class can actually typing the following figure, found not file is read only, you can write?

Here Insert Picture Description
Still do not know, maybe I am stupid to

Could it be that this class points here, but in itself is not here? (I do not understand the, I would not express)

Here Insert Picture Description
Right-item copy path, see the absolute path is not the path I said jdk environment installed, the path to build their own code but, even on the left shows the zip package jdk below.

Therefore, in this modification, then the JDK directory to build my own view is being modified.

Here Insert Picture Description

Sure enough, I just built a successful directory modifications, my idea is right, and this one has just modified the sourcePath this configuration, then once I went to see the official document idea how to say?
Here Insert Picture Description
Address: https: //www.jetbrains.com/help/idea/2016.3/sdk.html

Possible full translation into Chinese is not easy to understand, containing the source code for the SDK binaries included in the classpath set.here 其中包含类路径集中包含的SDK二进制文件的源代码。, is that the class path
Here Insert Picture Description
is here, yes, we most of the java source code in rt.jar in (off topic), classPath point here, but inside the source code through the above sourcePath have similarRedirect To the position just built up my own rules.

Woo ~

Ah, I think so, although it looks very awkward (looking to add a comment in the zip jdk's), but really solve the problem (a redirection), although not perfect, but enough friends, ha ha ha ha ha ha

other problems

Several landlord references there are other issues, though I do not have debug, but the first few steps and they say exactly the same, so the way to their problems also recorded, will be used later.

debug time, delays Alternative source availble for the class xxxx is disable

Here Insert Picture Description
Solution: Open setting => Debugger, select this option in the following figure.
Here Insert Picture Description

Daily News compilation java: insufficient OutOfMemory, hint system resources

Compilation Daily News java: OutOfMemory, suggesting insufficient system resources (https://blog.csdn.net/ljj821061514/article/details/52371037)

My original default setting is 700, into 1000, no problem
Here Insert Picture Description

Automatically associated to the code to make the code runs under the current project src directory (this, like I said the problem)

Automatically associated to the code to make the code runs under the current project src directory (in order not to affect the normal use jdk source, I created a 1.8study, the only difference is that the original src.zip replaced jdk1.8-sources -study the src directory) (https://blog.csdn.net/u011837804/article/details/80450809)
Here Insert Picture Description
original link: https: //blog.csdn.net/u010999809/article/details/101922489

Built manually (not through git clone, not recommended)

In this way a little tired, it is not recommended, it is better to find a good, in the front line on the shoulders of giants to github.
In this way from: https: //blog.csdn.net/qq_42191317/article/details/102772497

Brief introduction

In project development, when you view the jdk source is only allowed to read, you can not modify or add comments. In order to facilitate learning JDK source code, we first need to set up the environment, you can modify the JDK source code, add comments and other operations.

Step1: Create a project

Open IDEA, create a normal Java project, choose a good JDK.

Step2: Import sources

By choosing JDK8 version we create a project, and therefore automatically configures dependencies between good code, we need to do is to import source project.

JDK JDK source code is located under the src folder compression bag.

Open the directory where the new project

The src archive decompression to the src directory of the project

Environment is built, the next can begin JDK source code reading trip!

reference

https://blog.csdn.net/u010999809/article/details/101922489
https://www.jianshu.com/p/c00db010265b
https://blog.csdn.net/u011837804/article/details/80450809
https://blog.csdn.net/qq_42191317/article/details/102772497

Published 548 original articles · won praise 3281 · Views 2.58 million +

Guess you like

Origin blog.csdn.net/dataiyangu/article/details/105011703