通过将其源代码复制到我的项目中来调试rt.jar中的类 [英] Debug classes in rt.jar by copying their source to my project

查看:194
本文介绍了通过将其源代码复制到我的项目中来调试rt.jar中的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现有一个简单的方法来调试/破解我在项目中使用的第三方库。

I just found that there is an easy way to debug/hack third-party libraries that I use in my project.

例如,如果我想从spring-beans调试 org.springframework.beans.factory.support.AbstractBeanDefinition 所有我需要做的是在同一个包中使用相同的源在我的项目中创建一个这个类的副本。由于我的项目来源恰好在类路径中出现,所以 ClassLoader 将使用它们而不是Spring bean中的。然后我可以添加日志/断点/调整到标准类的行为,因为现在是我的控制源。

For example if I want to debug org.springframework.beans.factory.support.AbstractBeanDefinition from spring-beans all I need to do is to create a copy of this class in my project in the same package with the same source. As my project sources happen to appear earlier in the class path the ClassLoader will use them instead of the ones from spring-beans. Then I can add logging/breakpoints/tweaks to the standard class behavior as the source now is under my control.

Howere这不适用于标准Java类位于rt.jar。例如,它不适用于 java.util.HashMap 。有没有办法使用与rt.jar类相同的方法?

Howere this doesn't work with standard Java classes located in rt.jar. For example it doesn't work with java.util.HashMap. Is there any way to use the same approach with rt.jar classes?

推荐答案

你必须将替换类放在单独的目录或JAR文件,并使用 java 的 -Xbootclasspath / p 选项将其添加到引导 code>命令。您不应该分发任何使用此机制的代码来覆盖 rt.jar 类,但用于调试目的很好。

You would have to put your replacement classes in a separate directory or JAR file and prepend that to the bootstrap classpath using the -Xbootclasspath/p option to the java command. You should not distribute any code that uses this mechanism to override rt.jar classes but it's fine to use for debugging purposes.

请注意,您只应该使用引导类路径,以便他们真正需要的东西(特定的类文件替代rt.jar中的类)。您的应用程序的其余部分应保留在系统类加载器加载的正常类路径中,因为引导程序和系统加载程序(例如扩展名)之间可能存在其他加载程序,如果代码不可用,则代码将无法使用在引导类路径上。

Note that you should only use the bootstrap classpath for things they really need to be there (the specific class files that replace classes from rt.jar). The rest of your application should stay on the normal classpath to be loaded by the system classloader, as there may be other loaders in between the bootstrap and system loaders (e.g. for extensions) that your code wouldn't be able to use if it were on the bootstrap classpath.

这篇关于通过将其源代码复制到我的项目中来调试rt.jar中的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆