This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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

How to add a method for classLoader

chris liao

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 is not a final class you can try it.

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

Joined: Jul 24, 2005
Posts: 27
Thanks! if I extend URLClassLoader and add new method:removeURL in my new
please note the below code in URLClassLoader,
protected addURL(URL 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
Similar Threads
Adding JAR file to Classpath at Runtime
Using absolute path bundle file
Reflecting classes not in classpath
How to dynamically Add Classess to Running VMs class path
Remote Classpath Loader