6

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.

Siguza
  • 21,155
  • 6
  • 52
  • 89
Marius
  • 3,253
  • 5
  • 25
  • 29

4 Answers4

7

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!!

bestsss
  • 11,796
  • 3
  • 53
  • 63
2

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.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • So this means that if I have a bootstrap class in my project the one from bootstrap is loaded and not the one from my project? – Marius Jan 29 '11 at 18:04
  • To replace classes, I think you'll need `endorsed` not `ext`. Also, it's not the system property that you want to change, but to set an option on the command line. – Tom Hawtin - tackline Jan 29 '11 at 19:15
  • @Tom, could be and I confuse it with Tomcat/Jetty convention. – Thorbjørn Ravn Andersen Jan 29 '11 at 21:41
  • App servers and the like should be loading there classes from the system class loader (or a child). Classes from `ext`/the extension class loader should be loaded in preference to these. – Tom Hawtin - tackline Jan 30 '11 at 02:23
  • I always you the Xbootclasspath option, we have our own java.util.logging and a few more. I never touch ext (it's for extra append to bootstrap) since that could mess up standard applications – bestsss Jan 30 '11 at 21:44
0

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.

  • 1
    Welcome to StackOverflow! While answers are always appreciated, please try to summarise the points raised in the link you are providing in your answer itself. The link to the page could break in the future, which might [detract from your answer](http://meta.stackexchange.com/a/8259). A few sentences covering the key points from your link would make it so that your answer remains sound, even if the link no longer works :) – Obsidian Age Mar 08 '17 at 19:48
  • 1
    The link has indeed broken :/ – lennartVH01 May 14 '18 at 11:34
0

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.

Vincent Ramdhanie
  • 102,349
  • 23
  • 137
  • 192