• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Own URLClassloader...

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I want to hot-swap the implementation of a class which is packed in a jar-file.
for example:

Later I want to swap the implementation by providing a new jar-file.

This doesn't work. The new class gets never loaded.
I thought, that I have to write my own classloader to change the order of searching for classes in the method .
Everytime I try to call , I get the following exception:
java.lang.ClassNotFoundException: com.test.compA.ServiceAImpl
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.test.OwnClassLoader.loadClass(OwnClassLoader.java:43)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.test.ComponentManager.loadComponent(ComponentManager.java:176)
at myTest.MyTest.main(MyTest.java:12)
Caused by: java.util.zip.ZipException: invalid block type
at java.util.zip.InflaterInputStream.read(Unknown Source)
at sun.misc.Resource.getBytes(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
The ZipException does occur, when i call the method .
Any ideas? Thx in advance...
Chris
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This doesn't work. The new class gets never loaded.


It should work with URLClassLoader.
You must be sure that your jar files are NOT in the class path, so that the bootstrap class loader does not see them.
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic