I would like to see what a method in the Java API does. So I want the JDK Source Code.
Before I re-installed Linux I had the src.zip
package with all the official source code in it. I just had to tell Eclipse where this file is and I could see the code. But now I don't have the file anymore...
So the question is: Where can I find it?
This question is related to
java
Yes!! Got it!
I downloaded the Java Developer Kit (JDK) from sun.com for Linux. There was src.zip in. But first I uninstalled all Java packages with synaptic.
Well, I opened terminal in my Mac and type: "echo $JAVA_HOME" then I got the directory, went there and found src.zip
This file is contained in the standard JDK download. Also your Linux system probably have JDK in the repository. In my Ubuntu Linux file is located here: /usr/lib/jvm/java-6-sun-1.6.0.20/src.zip
Chances that you already got the source code with the JDK, it is matter of finding where it is. In case, JDK folder doesn't contain the source code:
sudo apt-get install openjdk-7-source
OSX Folks, search in homebrew formulas.
In ubuntu, the command above would put your souce file under: /usr/lib/jvm/openjdk-7/
Good news is that Eclipse will take you there already (How to bind Eclipse to the Java source code):
Follow the orange buttons
Sadly, as of this writing, DESPITE their own documentation readme, there is no src.zip in the JDK 7 or 8 install directories when you download the Windows version.
Note: perhaps this happens because many of us don't actually run the install .exe, but instead extract it. Many of us don't run the Java install (the full blown windows install) for security reasons....we just want the JDK put someplace out of the way where potential viruses cannot find it.
But their policy regarding the windows .exe (whatever it truly is) is indeed nuts, HOWEVER, the src.zip DOES exist in the linux install (a .tar.gz). There are multiple ways of extracting a .tar and a .gz, and I prefer the free "7Zip" utility.
Oracle, this is really beyond stupid.
Here the official link for jdk source. http://www.oracle.com/technetwork/java/javase/downloads/index.html (you may need to scroll to the bottom of the page)
The JDK 1.6 I'm currently using on OSX Mountain Lion did not come with a src.zip
either, and as far as i can tell there is no supported OSX JDK for 1.6 available anymore.
So I downloaded the OpenJDK source (using the links from the accepted answer (+1)) then ran:
cd ~/Downloads
mkdir jdk6src
cd jdk6src
tar xf ../openjdk-6-src-b27-26_oct_2012.tar.gz
cd jdk/src/share/classes
jar cf /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/src.jar *
(your file names and paths may vary...)
Associate that src.jar
with the appropriate Java platform in your IDE and you should be good to go.
There are some discrepancies between the OpenJDK source and the JDK I'm currently running (line numbers don't match up in the debugger, for one), but if all you want is a zip/jar to point your IDE to for the relatively few cases you need to peek at some code to understand how something works, then this should do the trick.
The official link no longer offers the original source code. The official link and casual google searches will land you with open jdk. Open jdk causes problems with android build unless the build script files are modified. The original package can be found here:
sudo add-apt-repository "deb http://ppa.launchpad.net/ferramroberto/java/ubuntu oneiric main"
This repo still has the sun-java6-source package. Credit: http://pulasthisupun.blogspot.com/2012/05/installing-sun-java-6-with-apt-get-in.html
I had this problem with my Ubuntu.
All I needed to do to get sources for my java insallation was:
sudo apt-get install sun-java6-source
Source: Stackoverflow.com