// NOTE:
// the urls used here are relative to the location of the build.xml
final URL url = new URL("file:./output/etc/test/implementation/loading/MyMBeans.jar");
// Retrieve the loader repository
LoaderRepository lr = LoaderRepository.getDefaultLoaderRepository();
// Should not be able to load the class
try
{
lr.loadClass("test.implementation.loading.support.Trivial");
fail("test.implementation.loading.support.Trivial is already visible");
}
catch (ClassNotFoundException expected) {}
// Add the URL to the repository twice
UnifiedClassLoader ucl1 = lr.newClassLoader(url, true);
UnifiedClassLoader ucl2 = lr.newClassLoader(url, true);
// Should be able to load the class
lr.loadClass("test.implementation.loading.support.Trivial");
// Remove one
ucl1.unregister();
// Should still be able to load the class
lr.loadClass("test.implementation.loading.support.Trivial");
// Remove the other
ucl2.unregister();
}