@Test public void test() { try { JarFile.registerUrlProtocolHandler(); LaunchedURLClassLoader classLoader = new LaunchedURLClassLoader( new URL[] { new URL("jar:file:/Users/fangjian/Develop/gitrepository/springboot-analysis/springboot-executable-jar/target/executable-jar-1.0-SNAPSHOT.jar!/lib/spring-boot-loader-1.3.5.RELEASE.jar!/") , new URL("jar:file:/Users/fangjian/Develop/gitrepository/springboot-analysis/springboot-executable-jar/target/executable-jar-1.0-SNAPSHOT.jar!/lib/spring-boot-1.3.5.RELEASE.jar!/") }, LaunchedURLClassLoaderTest.class.getClassLoader()); // classLoader.loadClass("org.springframework.boot.loader.JarLauncher"); // classLoader.loadClass("org.springframework.boot.SpringApplication"); classLoader.loadClass("org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration"); } catch (Exception e) { e.printStackTrace(); } }
@Test public void testFindOpenTracingAgentRules() throws Exception { File f = new File(System.getProperty("rules.path")); URL[] urls = new URL[1]; urls[0] = f.toURI().toURL(); try (LaunchedURLClassLoader loader = new LaunchedURLClassLoader(urls, ClassLoader.getSystemClassLoader())) { assertNotNull(loader.getResource("test.rule")); } }
@Override protected ClassLoader createClassLoader(URL[] urls) throws Exception { return new LaunchedURLClassLoader(urls, parent); }