简体   繁体   English

如何在Eclipse中查看Java SDK类(java.lang,java.util等)的源代码?

[英]How to see the source code for java SDK (java.lang, java.util, …) classes in Eclipse?

I want to read jar class files into my eclipse. 我想将jar类文件读入我的日食。 Suppose I wrote the following code: 假设我编写了以下代码:

List list = new ArrayList();

When I ctrl click on List, it shows two options. 当我按Ctrl键单击“列表”时,它显示两个选项。 One of the option is Open Declaration which will show the methods in List interfaces. 选项之一是“打开声明”,它将在List接口中显示方法。 But when I click it it shows source not found. 但是,当我单击它时,它显示找不到源。 I've added java-util-1.8.0.jar to it but still it won't work. 我已经将java-util-1.8.0.jar添加到了它,但仍然无法正常工作。 What am I doing wrong? 我究竟做错了什么?

you have to add Eclipse Plugin from 您必须从添加Eclipse插件

HELP -> Eclipse Marketplace 帮助-> Eclipse Marketplace

I personally used 我个人使用

Enhanced Class Decompiler 增强的类反编译器

just install it. 只需安装它。 and have fun. 玩得开心。

In order to see the source codes of JDK in eclipse you should add JDK path instead of JRE to your workspace or for a specific project SDK. 为了在Eclipse中查看JDK的源代码,应将JDK路径而不是JRE添加到工作区或特定的项目SDK。 I assume you are a developer and you've installed JDK on your system. 我假设您是一名开发人员,并且已在系统上安装了JDK

To do that: 要做到这一点:

  1. Right click and select Properties (or press Alt + Enter ) on your project. 右键单击并在项目上选择“属性”(或按Alt + Enter )。
  2. From the left tree styled menu select Java Build Path 从左侧树状菜单中选择“ Java构建路径”
  3. On the right select the Libraries 在右侧选择
  4. Select the JRE System Library 选择JRE系统库

在此处输入图片说明

  1. From the right side buttons click on edit, and edit the path from JRE location to points to the JDK location in your file system. 在右侧按钮上单击“编辑”,然后编辑从JRE位置指向文件系统中JDK位置的路径。

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

  1. Then click on Finish and the OK buttons of all opened dialogs to save the configurations and you set to go. 然后单击完成 ,然后单击所有打开的对话框中的确定按钮以保存配置,然后就可以开始了。

Hope this would be helpful. 希望这会有所帮助。

See if you have a src.zip file in your JDK Home. 查看您的JDK主页中是否有src.zip文件。 This would contain the source code for all Java SE libraries. 这将包含所有Java SE库的源代码。 Just unzip and browse the Java files to view the source code. 只需解压缩并浏览Java文件即可查看源代码。

If you want to debug through the source files then follow the instructions of attaching source folder in Eclipse as mentioned above. 如果要调试源文件,请按照上述在Eclipse中附加源文件夹的说明进行操作。

Assuming you project is Maven one.Go the Project --> Right Click --> Maven -->Download Javadoc & sources. 假设您的项目是Maven,请转到项目->右键单击-> Maven->下载Javadoc和源代码。 After performing these steps your problem will be resolved. 执行完这些步骤后,您的问题将得到解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM