public void close() throws IOException {
try {
for (Object l: getLoaders()) {
if (l.getClass().getName().equals("sun.misc.URLClassPath$JarLoader")) {
Field jarField = l.getClass().getDeclaredField("jar");
JarFile jar = (JarFile) getField(l, jarField);
if (jar != null) {
//System.err.println("CloseableURLClassLoader: closing " + jar);
jar.close();
}
}
}
} catch (Throwable t) {
IOException e = new IOException("cannot close class loader");
e.initCause(t);
throw e;
}
}
Close any jar files that may have been opened by the class loader.
Reflection is used to access the jar files in the URLClassLoader's
internal data structures. |