简体   繁体   English

使用Eclipse进行Java调试

[英]Java Debugging with Eclipse

I'm trying to debug a program that calls a function in the HashSet class, but I get a message saying: Source not found. 我正在尝试调试在HashSet类中调用函数的程序,但是我收到一条消息,提示:找不到源。 I know this is something with not finding the library files. 我知道这是没有找到库文件的事情。 Please, can someone guide me to how I can set it up? 拜托,有人可以指导我进行设置吗? Which library files should it be pointing to? 它应该指向哪些库文件?

Thank you very much for any pointers. 非常感谢您提供任何指导。

Finally got around to doing this awhile ago and I love it. 终于在不久前开始做这个,我很喜欢。

First you need to download the Java source. 首先,您需要下载Java源代码。 I got mine here (look for "Java SE 6 JDK Source Code"): http://www.oracle.com/technetwork/java/javase/downloads/index.html . 我在这里找到了(查找“ Java SE 6 JDK源代码”): http : //www.oracle.com/technetwork/java/javase/downloads/index.html Download that and stick it somewhere on disk that you can find easily. 下载该文件并将其粘贴在容易找到的磁盘上。 Keep in mind that the JAR you download has to actually be "installed" somewhere via you agreeing to a license agree (extract it with jav xvf jarname.jar and check the README it contains). 请记住,您下载的JAR实际上必须通过您同意许可协议的方式“安装”在某个地方(用jav xvf jarname.jar提取并检查其中包含的自述文件)。

For any JAR file on your CLASSPATH in Eclipse, you can add a source attachment to it to point to its source code. 对于Eclipse中CLASSPATH上的任何JAR文件,都可以向其添加源附件以指向其源代码。 The easiest thing to do is bring up the Package Explorer view. 最简单的操作是打开Package Explorer视图。 Underneath your project, you should see an item for your Java Runtime Environment (JRE) (mine is called "JRE System Library [JavaSE-1.6]"). 在项目下,您应该看到Java运行时环境(JRE)的项目(我的项目称为“ JRE系统库[JavaSE-1.6]”)。 Click on the expansion arrow for that and you'll see a list of JARs. 单击扩展箭头,您将看到一个JAR列表。

Most all of the Java classes you'll care about viewing are stored in "classes.jar". 您将关心的大多数Java类都存储在“ classes.jar”中。 Right-click on that JAR and select "Properties". 右键单击该JAR,然后选择“属性”。 In the left hand menu, select "Java Source Attachment". 在左侧菜单中,选择“ Java源附件”。 On the right side, click "External Folder" and find the source code that you downloaded and installed and put that folder into the "Location path" field. 在右侧,单击“外部文件夹”,然后找到您下载并安装的源代码,然后将该文件夹放入“位置路径”字段。 Hit "Apply" and "OK". 点击“应用”和“确定”。

Now you should be able to right click on any built-in Java class in your code and use the "Open Declaration" command or when debugging you will now step into the Java source. 现在,您应该能够右键单击代码中的任何内置Java类,并使用“打开声明”命令,或者在进行调试时,现在将进入Java源代码。

It's a great capability to have. 具有的强大功能。 Enjoy! 请享用!

HashSet is in JRE Package, so you can download JDK source and attach it into eclipse. HashSet位于JRE软件包中,因此您可以下载JDK源并将其附加到eclipse中。
An other way, when you can not find out the source package, you can use JD-Decompiler which has eclipse plugin to decompile your class, it work and show most like original source file. 另一种方法是,当您找不到源程序包时,可以使用具有eclipse插件的JD-Decompiler来反编译您的类,它可以正常工作并像原始源文件一样显示。

Choosing a JDK instead of JRE for the runtime environment worked for me! 为运行时环境选择JDK而不是JRE对我来说很有效!

NOTE:Make sure you have a JDK installed and not only JRE before proceeding. 注意:在继续操作之前,请确保已安装JDK,不仅是JRE。

  • Remove the current system JRE library: 删除当前系统的JRE库:

Right Click project -> properties -> Libraries -> Remove current JRE Library. 右键单击项目->属性->库->删除当前的JRE库。

  • Add other installed library to your project: 将其他已安装的库添加到您的项目中:

In the current dialogue box, click "add library". 在当前对话框中,单击“添加库”。 by default JRE system library is selected, if not, select it and click next. 默认情况下,将选择“ JRE”系统库,如果未选中,请选择它,然后单击“下一步”。 now select "Alternate JRE" and click "Installed JRE". 现在选择“备用JRE”,然后单击“已安装JRE”。 In the new dialogue box, click search and provide the path to your installed Java environments. 在新对话框中,单击“搜索”,并提供安装的Java环境的路径。

  • Finalize 完成

Select an installed JDK, and click OK. 选择一个已安装的JDK,然后单击“确定”。 Click FINISH and again OK to proceed. 单击完成,然后再次单击确定以继续。

Abdul, The best way is as the others explained to download the sources and attach them in the eclipse. 阿卜杜勒(Abdul),最好的方法是按照其他人的说明来下载源并将其附加在日食中。

The EASIEST way would be installing the java decompiler (JAD). 最简单的方法是安装Java反编译器(JAD)。 Take a look at http://jadclipse.sourceforge.net/install.html . 看看http://jadclipse.sourceforge.net/install.html Its explained there in 4 super simple steps :) 它在4个超级简单的步骤中说明了:)

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

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