如何编译jdk本身
我想自己编译jdk。我的意思是,我想修改jdk中的String.class来查看系统中创建的字符串对象。有没有办法修改jdk中的类?当我尝试通过修改 rt.jar 来修改源时,出现错误。
java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:394)
at java.lang.System.initProperties(Native Method)
at java.lang.System.initializeSystemClass(Unknown Source)
可能是签名有问题。
I want to compile jdk itself. I mean, I want to modify String.class in jdk to see created string objects in the system. Is there any way to modify classes in the jdk? When I try to modify source by modifying rt.jar, I got the error.
java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:394)
at java.lang.System.initProperties(Native Method)
at java.lang.System.initializeSystemClass(Unknown Source)
Probably there is a signature problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这看起来不像签名问题。看起来您更改了一些导致 Hashtable 取消引用空指针的内容。检查您所做的更改并了解这样做的原因。回想一下,Java 在某些情况下保留对 String 常量的内部引用。我猜你破坏了其中之一。
That doesn't look like a signature problem. It looks like you changed something that's causing Hashtable to dereference a null pointer. Review the change you made and see why it's doing this. Recall that Java keeps internal references to String constants in some conditions. I'm guessing you broke one of those.
那么,您可以从源代码下载、修改和构建 Java 6 的 OpenJDK 版本。 OpenJDK 站点 上提供了有关如何执行此操作的信息。
但请注意,对低级 Java 类(例如
String
)的更改可能会产生非专家难以理解的影响。结果很可能是 JVM 出现故障,导致println
或printStackTrace()
无法运行。Well, you can download, modify and build the OpenJDK releases of Java 6 from source. There's information on how to do this on the OpenJDK site.
But beware that changes to low-level Java classes (such as
String
) can have effects that are hard to a non-expert to understand. And the consequence could well be a JVM that fails in a way that makesprintln
orprintStackTrace()
inoperative.也许还有另一种方法:您下载 java.lang.String 原始源代码,进行修改并仅编译此类。
当您启动主程序时,请注意加载类:首先加载 String 类,然后加载 java 运行时类。请参阅 java 手册 和 - Xbootclasspath/p 选项以正确的顺序执行此操作。
There is maybe another way: you download java.lang.String original source, doing your modifications and compile only this class.
When you start your main programm be aware when loading classes: first load your String class then the java runtime classes. Refer to the java manual and the -Xbootclasspath/p options to do it in the proper order.
安装 JDK 时,您也可以选择安装源代码。这样做。或者单独下载源。然后
String.java
文件。java/lang
包中的String.java
。java -Xbootclasspath/p:<更改的字符串类路径> -cp <常规类路径> <您的应用程序主类>
但是更改 JDK 可能不是一个好主意,并且由于许可证限制,您不允许发布更改后的 JDK(至少不超过 1.6)。
是的,您的问题很可能出在其他地方。请记住选择没有被破坏;-)
When installing a JDK you may choose to install the sources as well. Do so. Or download the sources separately. Then
String.java
file.String.java
in packagejava/lang
.java -Xbootclasspath/p:<changed String classpath> -cp <regular classpath> <your application main class>
But changing the JDK might not be a good idea and you are not allowed to ship a changed JDK (at least up to 1.6) due license restrictions.
And yes, your problem is most likely somewhere else. Remember select isn't broken ;-)