47

I am searching the source code for rt.jar for Oracle JRE/JDK 6 Update 22. The src.zip, which is included with the delivery, does not contain all sources, for examples the sun.* (e.g. sun.reflect.Reflection) packages are missing.

Where can I get a complete src.zip?

durron597
  • 31,968
  • 17
  • 99
  • 158
MRalwasser
  • 15,605
  • 15
  • 101
  • 147

7 Answers7

23

sun.* sources are a part of JDK that is proprietary closed source Sun code (or Oracle since 2010).

Having said that, the package you're interested in (sun.reflect.) happens to be included in OpenJDK 7, and all of OpenJDK source is open.

You can get the source here: http://jdk7src.sourceforge.net/

rustyx
  • 80,671
  • 25
  • 200
  • 267
21

EDIT 2017-11-22:

This answer was written in 2010 where the world was very different. If you just need the sources for the JRE classes, use the JRE in a JDK build - the included src.zip file is recognized by most modern IDE's.

If you really, really need the full source (if you are unsure, you don't) then find a suitable OpenJDK debug build or build OpenJDK from source.


OLD 2010 ANSWER:

You can download the complete source code for the JDK from http://download.java.net/jdk6/source/

VERY IMPORTANT NOTE: This is under the Java Research License, which may taint you in a way incompatible with what you need to know this for.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
7

If you use Eclipse, here is how you can link to Java source files:

  1. As Thorbjørn Ravn Andersen mentioned, download the JDK source http://download.java.net/jdk6/source/ , and unzip the tar.gz file to a folder, say 'jdk.src';
  2. Open your java file that refers to a base java class (say Thread) that comes from the JDK;
  3. Tap F3 to open declaration, expect Eclipse to open a new tab with "source not found" message. It asks for the rt.jar source location, but you don't need to go through the trouble of compiling the JDK source to get it. Instead, click on the "attach source" button, in the "source attachment configuration" popup window, select "External Folder", then point to jdk.src/jdk/src/share/classes directory. Eclipse will then automatically load the newly found JDK class source code in the same window.
mtk
  • 13,221
  • 16
  • 72
  • 112
HaiXin Tie
  • 1,999
  • 3
  • 17
  • 14
6

http://jdk7src.sourceforge.net/

Cojones
  • 1,906
  • 22
  • 25
2

AFAIK part of JDK 6 originates from OpenJDK or is integrated into OpenJDK. So maybe you find more insights here:

Puce
  • 37,247
  • 13
  • 80
  • 152
1

The classes without source are closely based on the code from OpenJDK. You can download this source and you can see not only the Java code but the C code as well. This can be a good resource for JNI examples too.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

Rustam is right: souces of sun.* are not available. But you can always decompile *.class and see pretty readable code (unfortunately without javadocs :( ).

AlexR
  • 114,158
  • 16
  • 130
  • 208