英文:
How do I see the source code from packages I use in netbeans?
问题
关于在NetBeans中的Java项目,我如何查看我导入的类/包的源代码?
我已经阅读了之前的帖子,说我需要src.zip
文件。我从https://netbeans.org/downloads/8.0.2/zip.html下载了netbeans-8.0.2-201411181905-src.zip
文件。
作为一个练习,我谷歌了“String”类,并且看到它应该在java.lang.object
下面。然而,在src.zip
文件中我没有看到java.lang.object
文件夹(里面有很多源代码,但我不知道如何有效地浏览)。这是错误的版本吗?我的NetBeans顶部确实显示8.2版本。
我还尝试在项目窗口中的NetBeans库/JDK文件夹中逐个点击JAR文件。同样,有很多代码,但我觉得如果我要查找特定的类,我不能有效地浏览。
我需要能够快速查看我可能正在使用的任何包或类的源代码。
谢谢。
英文:
With regards to java projects in netbeans, how do I see the source code from the classes/packages I am importing?
I have read previous posts saying I need the src.zip file. I downloaded the netbeans-8.0.2-201411181905-src.zip file from https://netbeans.org/downloads/8.0.2/zip.html.
As a practice I googled the "String" class, and saw that it should be under java.lang.object. However, I do not see a java.lang.object folder in the src.zip file (there is lots of source code but I don't know how to navigate it effectively). Is this the wrong version? My netbeans dose say 8.2 at the top of the application.
I also tried clicking through the JAR files within the netbeans libraries/JDK folder in the project window. Again, lots of code but I feel I couldn't effectively navigate it if I was looking for a specific class.
I need to be able to quickly view source code from any packages or classes I may be working with.
Thank you.
答案1
得分: 1
已经下载了 src.zip 文件后,您需要在 NetBeans 中进行配置:
- 选择 工具 > Java 平台。
- 在 平台 面板中选择您要添加源代码的 JDK。
- 点击 Sources 选项卡,然后点击 Add JAR/Folder... 按钮。
- 导航到 src.zip,然后点击 Add JAR/Folder 按钮。
最后,点击 Close 关闭 Java 平台管理器 对话框。
然后您就能够查看该 JDK 的源代码。进行以下检查:
- 在您的 Java 源代码中,将光标放置在任何 JDK 类(例如
String
)上,或者其方法或构造函数上。 - 右键单击,在上下文菜单中选择 Navigate > Go to Source,您将被重定向到 JDK 类源代码中的适当位置。或者,按下 Ctrl + Shift + B 快捷键。
英文:
Having downloaded src.zip, you need to configure it in NetBeans:
-
Select Tools > Java Platforms.
-
Select the JDK for which you are adding the source in the Platforms panel.
-
Click the Sources tab, then click the Add JAR/Folder... button.
-
Navigate to src.zip and click the Add JAR/Folder button.
-
Finally, click Close to close the Java Platform Manager dialog.
Then you should be able to view the source of that JDK. To check:
-
In your Java source, place the cursor on any JDK class (e.g.
String
), or any of its methods or constructors. -
Right click, and from the context menu select Navigate > Go to Source and you should be redirected to the appropriate position within the source of the JDK class. Alternatively, press Ctrl + Shift + B.
答案2
得分: 0
如果这是一个Maven项目,在“项目”中转到“依赖项”,右键单击库,然后选择“下载源代码”。
英文:
If it's a maven project, in Projects
go to the Dependencies
, right click on the library and choose Download Sources
答案3
得分: 0
感谢大家,
总结一下这个经验,通过在NetBeans搜索栏中搜索类名,并点击所需类名,可以打开源代码文件。右键点击该文件的标签,然后点击“在项目中选择”选项,可以找到存储在JDK中的确切文件。
此外,projects.apache.org、http://jboss.org/projects 和 https://projects.apache.org/ 是寻找Java源代码的有用资源。
英文:
Thanks everyone,
To sum up this experience, searching for the class name in the netbeans search bar and clicking the desired class opens the source code file. Right clicking this file's tab and clicking "Select in projects" option exposes the exact file it is stored in within the JDK.
Also projects.apache.org, http://jboss.org/projects, and https://projects.apache.org/ are useful places to find java source code.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论