How to overwrite classes from jdk?

2019-02-25 12:53发布

I'm trying to change some classes from open jdk, so I'm creating the same package structure as the open jdk classes have and I'm changing the classes using netbeans. When i'm building the project if something is wrong in the overwritten classes i'm getting an error. If a successfully build my project it seems like the changes from my classes are not considered by the application, the open jdk classes are used instead. Any idea how can I use my classes and not the ones from openjdk ?

Example:

if i create the class sun.net.www.protocol.https.HttpsURLConnectionImpl in my project and I do some changes in it, I build the project, but when I run he application my changes do not appear, like the original class from openjdk is used, not my class.

4条回答
够拽才男人
2楼-- · 2019-02-25 13:04

This is what the extension classes is intended for.

See http://download.oracle.com/javase/1.5.0/docs/tooldocs/findingclasses.html#javalauncher for details. Basicall you either drop jars in the ext folder, or indicate with system properties what you want in front of the classpath overriding standard Java classes.

查看更多
冷血范
3楼-- · 2019-02-25 13:12

You should create your class in your own package and have the application that uses this class import your class instead. So you can create a class called HttpsURLConnectionImpl in package com.yourdomain.

Then in the application code make sure that you import:

  import com.yourdomain.HttpsURLConnectionImpl;

Then in your code your own class will be used.

查看更多
劳资没心,怎么记你
4楼-- · 2019-02-25 13:15

If there is anybody who has a problem with using -Xbootclasspath option I absolutely recommend the following page I have found some time ago: https://github.com/adrianmalik/hotspot-overriding-jdk . There is a detailed explanation how to use this option with a good (and working) code sample.

查看更多
聊天终结者
5楼-- · 2019-02-25 13:26

you need to change the bootstrap classpath java -X for more info, here is just the option you need exactly.

-Xbootclasspath/p:

And good luck hacking the source!!

查看更多
登录 后发表回答