custom class in java.* package - is it possible?

  • Follow


Hi all,

I would like to replace java.util.Calendar class - I need to slightly 
change it. Is it possible by providing custom classloader or..anything? 
Thanks for any hints.

Regards,
Maciek Zywno
0
Reply Maciek 3/16/2005 2:39:57 PM

> I would like to replace java.util.Calendar class - I need to slightly 
> change it. Is it possible by providing custom classloader or..anything?

You can use the non-standard option -Xbootclasspath with sun's jvm in order 
to load your own implementation of java.util.Calendar. However, this is not 
a particularly good idea since you can't distribute a program that overrides 
the core classes. Here is an excerpt from the doc for sun's jdk 1.5 :

"-Xbootclasspath/p:path
Specify a semicolon-separated path of directires, JAR archives, and ZIP 
archives to prepend in front of the default bootstrap class path. Note: 
Applications that use this option for the purpose of overriding a class in 
rt.jar should not be deployed as doing so would contravene the Java 2 
Runtime Environment binary code license. "


IMHO the proper way to do this is to get the source for the Calendar class 
(available from sun), make your changes and distribute this as a new class 
(that is to say in your own package, not java.*).

sincerely,

Cadet Reynaud-Plantey


0
Reply reynaud.danyel (1) 4/2/2005 9:03:55 PM


Danyel Reynaud-Plantey wrote:
>>I would like to replace java.util.Calendar class - I need to slightly 
>>change it. Is it possible by providing custom classloader or..anything?
> 
> 
> You can use the non-standard option -Xbootclasspath with sun's jvm in order 
> to load your own implementation of java.util.Calendar. However, this is not 
> a particularly good idea since you can't distribute a program that overrides 
> the core classes. Here is an excerpt from the doc for sun's jdk 1.5 :
> 
> "-Xbootclasspath/p:path
> Specify a semicolon-separated path of directires, JAR archives, and ZIP 
> archives to prepend in front of the default bootstrap class path. Note: 
> Applications that use this option for the purpose of overriding a class in 
> rt.jar should not be deployed as doing so would contravene the Java 2 
> Runtime Environment binary code license. "
> 
> 
> IMHO the proper way to do this is to get the source for the Calendar class 
> (available from sun), make your changes and distribute this as a new class 
> (that is to say in your own package, not java.*).
> 
> sincerely,
> 
> Cadet Reynaud-Plantey
> 
> 

Just FYI...

Whilst it true for overriding classes that are part of the Sun's own 
library (Java.*, sun.* etc) the use of -xbootclassPath is vital if you 
want to use a difference CORBA orb to the one that is shipped as part of 
the JRE.  The -xbootclassPath is widely used for this purpose.

The CORBA Orb interfaces are all packaged as omg.corba.orb.* packages 
which means the license does not effect use from overriding them.



0
Reply news248 (613) 4/2/2005 9:30:59 PM

If you code your own Calendar class it will override the
java.util.Calendar class. Or another way would be to just create a
class that extends the java.util.Calendar class and just override the
things you need to change.

0
Reply David.Federman (3) 4/3/2005 4:11:25 AM

Danyel Reynaud-Plantey wrote:
>>I would like to replace java.util.Calendar class - I need to slightly 
>>change it. Is it possible by providing custom classloader or..anything?

What problem are you having such that you can not simply
write a new subclass of java.util.Calendar?  Somwhere in
your code, I assume you are doing
Calendar myCal = Calendar.getInstance();

change that to:

Calendar myCal = fr.wanadoo.Calendar.getInstance();

Playing with class loaders sounds very excessive in this case.
There are various places in the JDK which WHEN NOT PROVIDED A CALENDAR, 
the API uses the system default one, but most that I know of can be 
overwritten with another calendar. I would be very interesting in 
understanding why this is not a possibility for the problem you have.

-Paul
0
Reply goodhillREMOVE (190) 4/4/2005 5:01:17 PM

4 Replies
235 Views

(page loaded in 0.302 seconds)

Similiar Articles:













7/25/2012 5:27:04 PM


Reply: