Java 如何在 Eclipse 中查看 JRE 的源代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/426084/
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
How do I view JRE's source code in Eclipse?
提问by
Using Eclipse I want to view the source code for a core Java class (E.g. java.util.concurrent.ConcurrentHashMap
) but when I navigate to the source using 'Open Declaration' it says 'Source not found' and gives me the option to attach the source.
使用 Eclipse 我想查看核心 Java 类(例如java.util.concurrent.ConcurrentHashMap
)的源代码,但是当我使用“打开声明”导航到源代码时,它显示“未找到源代码”,并为我提供了附加源代码的选项。
My question is; how do i attach the source? Where do i get the source .jar from for the java.util.concurrent
library?
我的问题是;我如何附上来源?我从哪里获得java.util.concurrent
库的源 .jar ?
采纳答案by jjnguy
You need to have the JDK installed. Then you can look in JDK_INSTALL_DIR\src.zip
您需要安装 JDK。然后你可以进去看看JDK_INSTALL_DIR\src.zip
For me it is C:\Program Files\java\jdk1.6.0_11\
(depends on your current version)
对我来说是C:\Program Files\java\jdk1.6.0_11\
(取决于你当前的版本)
You don't need to get a special open source version.
您不需要获得特殊的开源版本。
回答by Brian Fisher
You can go to http://openjdk.java.net/and download the latest builds of the openJDK project. I think this should give you what you need.
您可以访问http://openjdk.java.net/并下载 openJDK 项目的最新版本。我认为这应该给你你所需要的。
回答by Rob Hruska
There are a few good answers here on where to get the source. But a word of caution: I'd be wary about how you use it (if you're using it simply for reference). The API documentationis the only contract you should code against, and is what the developers will keep consistent/intact between releases. I wouldn't use the source find out implementation details and then code my applications with regard to those implementation details, as they may change between releases.
关于从哪里获得源代码,这里有一些很好的答案。但请注意:我会警惕你如何使用它(如果你只是为了参考而使用它)。该API文档是你应该对代码的唯一合同,而这也正是开发商将保持版本之间的一致/完好。我不会使用源代码找出实现细节,然后根据这些实现细节对我的应用程序进行编码,因为它们可能会在不同版本之间发生变化。
回答by Michael Rutherfurd
If you can't find the actual source you can also use a decompiler to regenerate source from the class file.
如果找不到实际的源代码,也可以使用反编译器从类文件中重新生成源代码。
Personally I use JAD combined with the JADClipse plugin to view source in Eclipse.
我个人使用 JAD 结合 JADClipse 插件在 Eclipse 中查看源代码。
回答by Michael Rutherfurd
You should be able to see "JRE System Library [jdk1.x.xxxx]" when you look at your project's Java Build Path.
当您查看项目的 Java 构建路径时,您应该能够看到“JRE 系统库 [jdk1.x.xxxx]”。
You can access the project build path configuration screen by: right clicking on the project -> Build Path -> Configure Build Path... You should be able to see the JRE System Library entry at the bottom of the list.
您可以通过以下方式访问项目构建路径配置屏幕:右键单击项目 -> 构建路径 -> 配置构建路径... 您应该能够在列表底部看到 JRE 系统库条目。
The easiest way to view the source for the class is to use the "Open Type" shortcut. The default for this shortcut is: Ctrl+ Shift+ T". The class you're looking for should appear as you type it's name.
查看类源的最简单方法是使用“打开类型”快捷方式。该快捷方式默认为:Ctrl+ Shift+ T。”你要找的类作为您键入它的名字应该出现。
回答by Michael Rutherfurd
When you are coding in Eclipse, press CTRLand click on any core Java class name in your source. Eclipse will now show a screen saying you don't have the sources installed. However, in this screen there is a link saying "Attach source...". Click that link and import the src.zip file from your JDK installation directory (src.zip). This should do the trick
在 Eclipse 中编码时,按下CTRL并单击源代码中的任何核心 Java 类名称。Eclipse 现在将显示一个屏幕,说明您没有安装源代码。但是,在此屏幕中有一个链接,上面写着“附加源...”。单击该链接并从 JDK 安装目录 (src.zip) 导入 src.zip 文件。这应该可以解决问题
回答by Dmitry Sobolev
回答by ruediste
For ubuntu, install openjdk-6-source and use /usr/lib/jvm/java-6-openjdk/src.zip
对于 ubuntu,安装 openjdk-6-source 并使用 /usr/lib/jvm/java-6-openjdk/src.zip
回答by Francisco J. Güemes Sevilla
Outside Eclipse you can see the JDK sources on javasourcecode.org. On this page you can switch from the oficial API documentation to the source code and viceversa.
在 Eclipse 之外,您可以在javasourcecode.org上查看 JDK 源代码。在此页面上,您可以从官方 API 文档切换到源代码,反之亦然。
回答by Rocky
Right click on the project -> Build Path -> Configure Build Path. Now edit your jre > select 2nd option alternate jre -> select any jdk (notjre). Finish, Now open any class by ctrl + click, Its source code will display.
右键单击项目-> 构建路径-> 配置构建路径。现在编辑您的 jre > 选择第二个选项备用 jre - > 选择任何 jdk(不是jre)。完成,现在通过 ctrl + click 打开任何类,它的源代码将显示出来。