在哪里可以找到 Java JDK 源代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2896727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where to find Java JDK Source Code?
提问by Martijn Courteaux
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...
我想看看 Java API 中的方法是做什么的。所以我想要 JDK 源代码。在我重新安装 Linux 之前,我有一个src.zip
包含所有官方源代码的包。我只需要告诉 Eclipse 这个文件在哪里,我就可以看到代码。但是现在我没有文件了...
So the question is: Where can I find it?
所以问题是:我在哪里可以找到它?
采纳答案by Jon Skeet
回答by vbezhenar
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
此文件包含在标准 JDK 下载中。此外,您的 Linux 系统可能在存储库中有 JDK。在我的 Ubuntu Linux 文件中位于:/usr/lib/jvm/java-6-sun-1.6.0.20/src.zip
回答by Martijn Courteaux
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.
我从 sun.com 下载了适用于 Linux 的 Java Developer Kit (JDK)。里面有 src.zip。但首先我卸载了所有带有突触的 Java 包。
回答by Xorty
I had this problem with my Ubuntu.
我的 Ubuntu 有这个问题。
All I needed to do to get sources for my java insallation was:
我需要做的就是为我的 Java 安装获取源代码:
sudo apt-get install sun-java6-source
回答by frewper
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)
这里是jdk源的官方链接。 http://www.oracle.com/technetwork/java/javase/downloads/index.html(您可能需要滚动到页面底部)
回答by Jitendra Kulkarni
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:
官方链接不再提供原始源码。官方链接和随意的谷歌搜索将为您提供开放的 jdk。除非修改构建脚本文件,否则打开 jdk 会导致 android 构建出现问题。原始包可以在这里找到:
sudo add-apt-repository "deb http://ppa.launchpad.net/ferramroberto/java/ubuntuoneiric main"
sudo add-apt-repository “deb http://ppa.launchpad.net/ferramroberto/java/ubuntuoneiric 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
这个 repo 仍然有 sun-java6-source 包。信用:http: //pulasthisupun.blogspot.com/2012/05/installing-sun-java-6-with-apt-get-in.html
回答by MisterEd
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.
我目前在 OSX Mountain Lion 上使用的 JDK 1.6 也没有附带,src.zip
据我所知,不再支持 1.6 的 OSX JDK。
So I downloaded the OpenJDK source (using the links from the accepted answer (+1)) then ran:
所以我下载了 OpenJDK 源代码(使用来自已接受答案 (+1) 的链接)然后运行:
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.
将其src.jar
与 IDE 中的适当 Java 平台相关联,您应该很高兴。
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.
OpenJDK 源代码和我当前正在运行的 JDK 之间存在一些差异(例如,调试器中的行号不匹配),但是如果您只需要一个 zip/jar 来将您的 IDE 指向相对在少数情况下,您需要查看一些代码以了解某些东西是如何工作的,那么这应该可以解决问题。
回答by amertkara
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:
您可能已经获得了 JDK 的源代码,重要的是要找到它的位置。如果 JDK 文件夹不包含源代码:
sudo apt-get install openjdk-7-source
OSX Folks, search in homebrew formulas.
OSX Folks,搜索自制公式。
In ubuntu, the command above would put your souce file under: /usr/lib/jvm/openjdk-7/
在 ubuntu 中,上面的命令会将你的源文件放在:/usr/lib/jvm/openjdk-7/
Good news is that Eclipse will take you there already (How to bind Eclipse to the Java source code):
好消息是 Eclipse 会带你去那里(如何将 Eclipse 绑定到 Java 源代码):
Follow the orange buttons
跟随橙色按钮
回答by amertkara
Sadly, as of this writing, DESPITE their own documentation readme, there is nosrc.zip in the JDK 7 or 8 install directories when you download the Windows version.
遗憾的是,在撰写本文时,尽管有他们自己的文档自述文件,但当您下载 Windows 版本时,JDK 7 或 8 安装目录中没有src.zip 。
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.
注意:可能发生这种情况是因为我们中的许多人实际上并未运行安装 .exe,而是将其解压缩。出于安全原因,我们中的许多人不运行 Java 安装(完整的 Windows 安装)......我们只是希望 JDK 把一些地方放在潜在病毒无法找到的地方。
But their policy regarding the windows .exe (whatever it truly is) is indeed nuts, HOWEVER, the src.zip DOESexist 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.
但是他们关于 windows .exe(无论它真正是什么)的政策确实很疯狂,但是,src.zip确实存在于 linux 安装(.tar.gz)中。有多种提取 .tar 和 .gz 的方法,我更喜欢免费的“7Zip”实用程序。
- download the Linux 64 bit .tar.gz
- use 7zip to uncompress the .tar.gz to a .tar
- use 7zip to extract the .tar to the installation directory
- src.zip will be waiting for you in that installation directory.
- pull it out and place it where you like.
- 下载 Linux 64 位 .tar.gz
- 使用 7zip 将 .tar.gz 解压缩为 .tar
- 使用 7zip 将 .tar 解压到安装目录
- src.zip 将在该安装目录中等待您。
- 把它拉出来,放在你喜欢的地方。
Oracle, this is really beyond stupid.
甲骨文,这真是超越愚蠢。
回答by petery
Well, I opened terminal in my Mac and type: "echo $JAVA_HOME" then I got the directory, went there and found src.zip
好吧,我在我的 Mac 上打开终端并输入:“echo $JAVA_HOME”然后我得到了目录,去那里找到了 src.zip