use of java.rmi.server.RMIClassLoader in project jdk8u_jdk by JetBrains.
the class DelegateToContextLoader method main.
public static void main(String[] args) throws Exception {
/*
* Set a security manager so that RMI class loading will not
* be disabled.
*/
TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
URL codebaseURL = TestLibrary.installClassInCodebase(className, "codebase");
/* Create a URLClassLoader to load from the codebase and set it
* as this thread's context class loader. We do not use the
* URLClassLoader.newInstance() method so that the test will
* compile with more early versions of the JDK.
*
* We can get away with creating a class loader like this
* because there is no security manager set yet.
*/
ClassLoader codebaseLoader = new URLClassLoader(new URL[] { codebaseURL });
Thread.currentThread().setContextClassLoader(codebaseLoader);
File srcDir = new File(TestLibrary.getProperty("test.classes", "."));
URL dummyURL = new URL("file", "", srcDir.getAbsolutePath().replace(File.separatorChar, '/') + "/x-files/");
try {
/*
* Attempt to load the target class from the dummy URL;
* it should be found in the context class loader.
*/
Class cl = RMIClassLoader.loadClass(dummyURL, className);
System.err.println("TEST PASSED: loaded class: " + cl);
} catch (ClassNotFoundException e) {
throw new RuntimeException("TEST FAILED: target class in context class loader " + "not found using RMIClassLoader");
}
}
Aggregations