wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes How to add a method for classLoader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to add a method for classLoader" Watch "How to add a method for classLoader" New topic
Author

How to add a method for classLoader

chris liao
Greenhorn

Joined: Jul 24, 2005
Posts: 27
I want to extend URLClassLoader,Which containered a method: addURL(URL url),
but why not give us another method: removeURL(URL url) in URLClassLoader??

Now, I need a meothd to remove some url,but I don't how to do about this.
Please help me !
yash Vi
Ranch Hand

Joined: Jul 17, 2005
Posts: 41
can try extend the URLClassloader and create your own class with a remove method on it.as it is not a final class you can try it.


Thanks for your reply and time.<br />Windows 2000,j2sdk1.4.2_08
chris liao
Greenhorn

Joined: Jul 24, 2005
Posts: 27
Thanks! if I extend URLClassLoader and add new method:removeURL in my new
ClassLoader.
please note the below code in URLClassLoader,
protected addURL(URL url){
ucp.addURL(url);
}

In fact,no removeURL method in URLClassLoader,but I need it appear in my new classLoader,I don't how to write the code about it.
please help me !
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I don't think you can remove a URL from the class loader's list without maybe using reflection to change some private methods to public. That would be a Very Dangerous Thing in most cases.

You could get the current list of URLs and create a new class loader that has all off the current ones except the one you want to remove.

See if the difference between these two lines makes sense:


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to add a method for classLoader