We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this questionI would like to see what a method in the Java API does. So I want the JDK source code.
Before I reinstalled 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...
Where开发者_StackOverflow中文版 can I find it?
You haven't said which version you want, but an archive of the JDK 8 source code can be downloaded here, along with JDK 7 and JDK 6.
Additionally you can browse or clone the Mercurial repositories: 8, 7, 6.
Chances that you already got the source code with the JDK, is a matter of finding where it is. In that case, the JDK folder doesn't contain the source code:
sudo apt-get install openjdk-7-source
OS X folks, search in Homebrew formulas.
In Ubuntu, the command above would put your source file under:
/usr/lib/jvm/openjdk-7/
The 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.
- download the Linux 64 bit .tar.gz
- use 7-Zip to uncompress the .tar.gz to a .tar
- use 7-Zip to extract the .tar to the installation directory
- File src.zip will be waiting for you in that installation directory.
- pull it out and place it where you like.
Oracle, this is really beyond stupid.
I had this problem with my Ubuntu.
All I needed to do to get sources for my Java installation was:
sudo apt-get install sun-java6-source
The JDK 1.6 I'm currently using on OS X v10.8 (Mountain Lion) did not come with a src.zip
either, and as far as I can tell there is no supported Mac OS X 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.
This file is contained in the standard JDK download. Also your Linux system probably has the JDK in the repository. In my Ubuntu Linux, the file is located in /usr/lib/jvm/java-6-sun-1.6.0.20/src.zip.
In JDK 8, the source can be found in <JDK installation directory>/src.zip. Now in some intermediate releases this ZIP file was missing, but again it is available.
Make sure that you select the source as well from the installation wizard.
Here the official link for the JDK source: http://www.oracle.com/technetwork/java/javase/downloads/index.html
(You may need to scroll to the bottom of the page.)
Well, I opened terminal in my Mac and typed:
echo $JAVA_HOME
Then I got the directory, went there and found src.zip.
Yes!! I got it!
I downloaded the Java Developer Kit (JDK) from sun.com for Linux. There was file src.zip in. But first I uninstalled all Java packages with Synaptic.
The official link no longer offers the original source code. The official link and casual Google searches will land you with OpenJDK.
OpenJDK causes problems with an 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 repository still has the sun-java6-source package.
Credit: Installing sun-java-6 with apt-get in Linux
精彩评论