简体   繁体   English

如何在Eclipse中进入核心java类方法?

[英]How can I step into a core java class method in Eclipse?

Hi I am going to dig a little more in Java so I would like to see how the program executed in the core class. 嗨,我将在Java中挖掘更多,所以我想看看程序是如何在核心类中执行的。 For example, I would like to know how String.chatAt() is implemented, so I set breakpoint and tried to step into with debug mode. 例如,我想知道如何实现String.chatAt() ,所以我设置断点并试图进入调试模式。 But I failed, I set bp at the second line when the program hit it, I used step into it still continue to the third line. 但是我失败了,当程序命中时我在第二行设置了bp,我用它进入它还是继续到第三行。

String a = "1231231241241";
char b = a.charAt(0);
System.out.println(b);

I think it should go into the source and show "no source found" and then give me a chance to attach the source file, right? 我认为它应该进入源代码并显示“找不到源代码”,然后给我一个附加源文件的机会,对吧? But why it cannot get in? 但为什么它不能进入​​呢? I can only use ctrl+right click on a method to get into source and attach. 我只能使用ctrl+right单击一个方法进入源和附加。

It might be that your Eclipse is not setup to run with JDK, it might run with JRE instead. 可能是您的Eclipse没有设置为使用JDK运行,它可能会与JRE一起运行。
Check this link . 检查此链接
Also, I might suggest you to try and use Maven for your Java projects management, it makes the life so much easier, when you get a grasp of it. 此外,我可能会建议您尝试使用Maven进行Java项目管理,当您掌握它时,它会让生活变得更加轻松。

Most likely, you have the "Step filtering" functionality activated. 最有可能的是,您已激活“步骤过滤”功能。

When debugging, it can sometimes be a bit annoying when the debugger steps into trivial classes whose internals you were not really interested in. Because of this, you can configure "Step filters". 在调试时,当调试器进入你不感兴趣的内部的普通类时,它有时会有点烦人。因此,你可以配置“步骤过滤器”。 Classes or packages that are added as step filters will be ignored by the "Step into" operation. “步入”操作将忽略作为步骤过滤器添加的类或包。

If you want to configure which classes/packages should be included in the step filter, you can go to: 如果要配置步骤过滤器中应包含哪些类/包,可以转到:
Window --> Preferences --> Java --> Debug --> Step Filtering
My guess is that you have a java.* package filter defined there, meaning that the debugger will never step into any class within a package which starts with "java". 我的猜测是你在那里定义了一个java.*包过滤器,这意味着调试器永远不会进入以“java”开头的包中的任何类。 Uncheck this package filter if you want to be able to step into java.lang.String 如果您希望能够进入java.lang.String取消选中此包过滤器

Alternatively, if you want to activate/deactivate step filtering completely, you can do this by clicking the Use step filtering button in the debug view, as shown below: 或者,如果要完全激活/取消激活步骤过滤,可以通过单击调试视图中的“ Use step filtering按钮来执行此操作,如下所示:

切换步骤过滤

To be able to look at the code of libriaries you are using in your project you should configure your build path by attaching the soruces and JavaDoc. 为了能够查看您在项目中使用的libriaries代码,您应该通过附加soruces和JavaDoc来配置构建路径。

Source Lookup 来源查询

Seems like you dont have the "Source Attachment" set. 好像你没有设置“源附件”。 Go to Preferences -> Java -> Installed JREs. 转到首选项 - > Java - >已安装的JRE。 Select the JRE you use and click "Edit", then set the Source Attachment to the src.zip that comes with the jdk by selecting the jars and clicking "Source Attachment" :). 选择您使用的JRE并单击“编辑”,然后通过选择jar并单击“Source Attachment”:)将Source Attachment设置为jdk附带的src.zip。 You can do this with all of the jars at the same time by selecting them via shift-click. 您可以通过shift-click选择它们,同时对所有罐子进行此操作。

例如,在这个System.out.println(“test”)代码段中,如果你想进入System类,只需单击System并单击F3,如果你还没有附加,你将被重定向到附加源代码。附上了jdk的src文件夹

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

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