File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to unload a class/jar from the classpath under Weblogic environment

 
Chengwei Lee
Ranch Hand
Posts: 884
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

Did some search on the ranch & google & found that inorder for a class to be unloaded, its ClassLoader must be able to be garbage collected.

What I'm trying to do is to unload a class that is on my classpath. So I get class's ClassLoader, set it to null & invoke System.gc(). Tried to load the class (at a different location) but seems that the same old class is being loaded again.

So what exact codes/steps that I should have inorder to change my old Jar to a newer Jar (different location)?

Any help is appreciated.

Thanks!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't reliably make the JVM garbage collect an object, so I think this approach will have trouble. I looked at JUnit source code because the GUI runner tests new versions of classes without stopping and restarting. It just uses a new ClassLoader to load the new version. It might be customized to NOT call its parent loader first. It looks awfully simple but I haven't experimented to see how it works. See if that does what you need. Google for "java reload class" and find some other examples, too.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic