Java 从哪里获得 rt.jar 的完整源代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4379050/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 16:44:00  来源:igfitidea点击:

Where to get full source code for rt.jar?

java

提问by MRalwasser

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.

我正在为 Oracle JRE/JDK 6 Update 22 搜索 rt.jar 的源代码。交付中包含的 src.zip 不包含所有源代码,例如 sun.*(例如 sun.reflect.Reflection ) 包丢失。

Where can I get a complete src.zip?

我在哪里可以获得完整的 src.zip?

采纳答案by Thorbj?rn Ravn Andersen

EDIT 2017-11-22:

编辑 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.

这个答案是在 2010 年写的,当时世界非常不同。如果您只需要 JRE 类的源代码,请在 JDK 构建中使用 JRE - 大多数现代 IDE 都可以识别包含的 src.zip 文件。

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.

如果您真的,真的需要完整的源代码(如果您不确定,则不需要),然后找到合适的 OpenJDK 调试版本或从源代码构建 OpenJDK。



OLD 2010 ANSWER:

旧的 2010 答案:

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

您可以从http://download.java.net/jdk6/source/下载 JDK 的完整源代码

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.

非常重要的注意事项:这是在 Java Research License 下的,这可能会以与您需要了解的内容不兼容的方式污染您。

回答by rustyx

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

sun.*源代码是 JDK 的一部分,它是专有的封闭源 Sun 代码(或自 2010 年以来的 Oracle)。

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.

话虽如此,您感兴趣的包 (sun.reflect.) 恰好包含在 OpenJDK 7 中,并且所有 OpenJDK 源代码都是开放的。

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

您可以在此处获取源代码:http: //jdk7src.sourceforge.net/

回答by AlexR

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

Rustam 是对的:souces of sun.* 不可用。但是你总是可以反编译 *.class 并看到非常可读的代码(不幸的是没有 javadocs :( )。

回答by Puce

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

JDK 6 的 AFAIK 部分源自 OpenJDK 或集成到 OpenJDK 中。所以也许你会在这里找到更多的见解:

回答by Peter Lawrey

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.

没有源代码的类紧密基于 OpenJDK 的代码。您可以下载这个源代码,不仅可以看到 Java 代码,还可以看到 C 代码。这也可以是 JNI 示例的一个很好的资源。

回答by HaiXin Tie

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

如果您使用 Eclipse,可以通过以下方式链接到 Java 源文件:

  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 F3to 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/classesdirectory. Eclipse will then automatically load the newly found JDK class source code in the same window.
  1. 正如 Thorbj?rn Ravn Andersen 提到的,下载 JDK 源http://download.java.net/jdk6/source/,并将 tar.gz 文件解压缩到一个文件夹中,比如“jdk.src”;
  2. 打开引用来自 JDK 的基本 Java 类(比如 Thread)的 Java 文件;
  3. 点击F3打开声明,希望 Eclipse 打开一个带有“未找到源”消息的新选项卡。它要求提供 rt.jar 源代码位置,但您无需通过编译 JDK 源代码来获取它。而是点击“附加源”按钮,在“源附件配置”弹出窗口中,选择“外部文件夹”,然后指向jdk.src/jdk/src/share/classes目录。然后 Eclipse 将在同一窗口中自动加载新找到的 JDK 类源代码。