View Java Source In Eclipse for Windows

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.

Requirements: 

javajdklinux

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.

javajdklinuxdownload

Right click on .gz file > 7-Zip > Extract Here

Right click on non .gz file > Extract Here

javajdklinuxextract

A new folder will be created, browse to new folder, locate src.zip.

Right click > 7-Zip > Extract to “\src”

javajdklinuxextractsrc

A src folder will be created.

javajdklinuxextractsrcfolder

Next, open your eclipse and create a new java project. The new java project should have a src folder.

eclipsesrcview

Right click on the eclipse src folder > Properties, take note of the Location.

eclipsesrclocation

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

eclipsesrccopy

Refresh your project in eclipse.

eclipsesrcproblems

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

eclipseslibraries

Click on the JRE System Library > Remove

Click Add Library > JRE System Library > Alternate JRE > Finish > OK

eclipsesaltjre

You will notice we still have a few problems.

eclipsesrcproblems2

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.

Click OK

eclipsesrcproblems3

There should be no more problems, you are now able to inspect java source in eclipse editor.

eclipsejdksource

Posted in Java
One comment on “View Java Source In Eclipse for Windows
  1. […] a previous post I outlined the steps to view java source code in […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: