JCL
JCL copied to clipboard
java.lang.LinkageError
@Test
public void test() throws Exception {
JarClassLoader jcl = new JarClassLoader();
//adding Test.jar (consist of com.google.at.mortezaadi.Sample)
//to JCL
jcl.add("test/Test.jar");
// insuring JCL can load the class
Class loadedClass = jcl.loadClass(
"com.google.at.mortezaadi.Sample");
assertNotNull(loadedClass);
// unload class file inside the Test.Jar
jcl.unloadClass("com.google.at.mortezaadi.Sample");
// insuring jcl unloaded the class
boolean classExsist = false;
try{
jcl.loadClass("com.google.at.mortezaadi.Sample");
classExsist = true;
}catch(Exception ex) {
}
assertTrue(!classExsist);
/******************************/
//adding jar file again
jcl.add("test/Test.jar");
/** loading file again THROWS EXCEPTION
* java.lang.LinkageError: loader (instance of org/xeustechnologies/jcl/JarClassLoader): attempted duplicate class definition for name: "com/google/at/mortezaadi/Sample"
*/
loadedClass = jcl.loadClass(
"com.google.at.mortezaadi.Sample");
}
unload(String name) only remove the class entry from classPathResource. So, it cannot unload class from PermGen.
Only way i think is set JarclassLoader to null.