As my journey into java development continues, I found an opportunity to investigate core java source code. My interest was the method String.contentEquals(). Curious in the difference between String.equals() and String.contentEquals(), look to java source code.
UPDATE: View Java Source In Eclipse for Windows – The Easy Way
Please note, I am not attempting to compile my own jdk library. Information for compiling the jdk from scratch can be found here http://openjdk.java.net/. Also the openjdk will contain more source code than Oracle JDK. http://en.wikipedia.org/wiki/Free_Java_implementations#Sun.27s_November_2006_announcement
Finally there are sites like http://www.grepcode.com/ that you can view source there if you like.
The following steps outline how I load java source code into eclipse for easy viewing.
- 7-Zip – http://www.7-zip.org/
- Eclipse Standard – https://www.eclipse.org/downloads/index.php
- Java SE Development Kit for Linux – http://www.oracle.com/technetwork/java/javase/downloads/index.html
Download the .gz file. In my environment I am running x64.
The reason I am using the linux build is because the jt.jar file contains a few classes that don’t exist in the windows build.
Right click on .gz file > 7-Zip > Extract Here
Right click on non .gz file > Extract Here
A new folder will be created, browse to new folder, locate src.zip.
Right click > 7-Zip > Extract to “\src”
A src folder will be created.
Next, open your eclipse and create a new java project. The new java project should have a src folder.
Right click on the eclipse src folder > Properties, take note of the Location.
Copy the contents of the extracted jdk src folder into the src of your java project.
In my example, I have D:\jdk\jdk1.7.0_51\src > C:\Lab\JavaSource\src
Refresh your project in eclipse.
You will notice right away of access restriction build problems. Lets resolve these problems.
In eclipse, right click on your project > Properties > Java Build Path > Libraries
Click on the JRE System Library > Remove
Click Add Library > JRE System Library > Alternate JRE > Finish > OK
You will notice we still have a few problems.
This is the reason I am using the linux build, the jt.jar file contains the UNIXToolkit class that doesn’t exist in the windows build.
Lets resolve these problems
Right click on your project > Properties > Java Build Path > Libraries > Add External JARs…
Locate the rt.jar from your jdk download. My locations was \jdk1.7.0_51\jre\lib.
There should be no more problems, you are now able to inspect java source in eclipse editor.
[…] a previous post I outlined the steps to view java source code in […]