@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(); } }
public BootApplicationConfigurationMetadataResolver(ClassLoader parent) { this.parent = parent; JarFile.registerUrlProtocolHandler(); try { Resource[] globalResources = new PathMatchingResourcePatternResolver(ApplicationConfigurationMetadataResolver.class.getClassLoader()).getResources(WHITELIST_PROPERTIES); loadWhiteLists(globalResources, globalWhiteListedClasses, globalWhiteListedProperties); } catch (IOException e) { throw new RuntimeException("Error reading global white list of configuration properties", e); } }
protected Archive getNestedArchive(Entry entry) throws IOException { JarEntry jarEntry = ((JarFileEntry) entry).getJarEntry(); if (jarEntry.getComment().startsWith(UNPACK_MARKER)) { return getUnpackedNestedArchive(jarEntry); } JarFile jarFile = this.jarFile.getNestedJarFile(jarEntry); return new JarFileArchive(jarFile); }
@Test public void resolveFromNested() throws Exception { File file = this.temporaryFolder.newFile(); TestJarCreator.createTestJar(file); JarFile jarFile = new JarFile(file); URL url = jarFile.getUrl(); LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { url }, null); URL resource = loader.getResource("nested.jar!/3.dat"); assertThat(resource.toString()).isEqualTo(url + "nested.jar!/3.dat"); assertThat(resource.openConnection().getInputStream().read()).isEqualTo(3); }
public BootApplicationConfigurationMetadataResolver(ClassLoader parent) { this.parent = parent; JarFile.registerUrlProtocolHandler(); try { Resource[] globalResources = new PathMatchingResourcePatternResolver( ApplicationConfigurationMetadataResolver.class.getClassLoader()).getResources(WHITELIST_PROPERTIES); loadWhiteLists(globalResources, globalWhiteListedClasses, globalWhiteListedProperties); } catch (IOException e) { throw new RuntimeException("Error reading global white list of configuration properties", e); } }
public JarFileArchive(JarFile jarFile) { this.jarFile = jarFile; ArrayList<Entry> jarFileEntries = new ArrayList<Entry>(); for (JarEntryData data : jarFile) { jarFileEntries.add(new JarFileEntry(data)); } this.entries = Collections.unmodifiableList(jarFileEntries); }
protected Archive getNestedArchive(Entry entry) throws IOException { JarEntryData data = ((JarFileEntry) entry).getJarEntryData(); if (data.getComment().startsWith(UNPACK_MARKER)) { return getUnpackedNestedArchive(data); } JarFile jarFile = this.jarFile.getNestedJarFile(data); return new JarFileArchive(jarFile); }
@Override public Archive getFilteredArchive(final EntryRenameFilter filter) throws IOException { JarFile filteredJar = this.jarFile.getFilteredJarFile(new JarEntryFilter() { @Override public AsciiBytes apply(AsciiBytes name, JarEntryData entryData) { return filter.apply(name, new JarFileEntry(entryData)); } }); return new JarFileArchive(filteredJar); }
/** * Launch the application. This method is the initial entry point that should be * called by a subclass {@code public static void main(String[] args)} method. * @param args the incoming arguments */ protected void launch(String[] args) { try { JarFile.registerUrlProtocolHandler(); ClassLoader classLoader = createClassLoader(getClassPathArchives()); launch(args, getMainClass(), classLoader); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } }
@Test public void resolveFromNested() throws Exception { File file = this.temporaryFolder.newFile(); TestJarCreator.createTestJar(file); JarFile jarFile = new JarFile(file); URL url = jarFile.getUrl(); LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { url }, null); URL resource = loader.getResource("nested.jar!/3.dat"); assertThat(resource.toString(), equalTo(url + "nested.jar!/3.dat")); assertThat(resource.openConnection().getInputStream().read(), equalTo(3)); }
public static void start (String []args) { bootstrap = new Bootstrap (); try { JarFile.registerUrlProtocolHandler(); classLoader = bootstrap.createClassLoader(bootstrap.getClassPathArchives()); bootstrap.launch(args, bootstrap.getMainClass(), classLoader, true); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } }
public static synchronized void start(String[] args) throws Exception { warlauncher = new MidPointWarLauncher(); try { JarFile.registerUrlProtocolHandler(); classLoader = warlauncher.createClassLoader(warlauncher.getClassPathArchives()); warlauncher.launch(args, warlauncher.getMainClass(), classLoader, true); } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.append("Could not start MidPoint application").append(";").append(ex.getLocalizedMessage()); throw new Exception(sb.toString(), ex); } }
public JarFileArchive(File file, URL url) throws IOException { this(new JarFile(file)); this.url = url; }
public JarFileArchive(JarFile jarFile) { this.jarFile = jarFile; }
private void clearCache(URLConnection connection) throws IOException { Object jarFile = ((JarURLConnection) connection).getJarFile(); if (jarFile instanceof JarFile) { ((JarFile) jarFile).clearCache(); } }
/** * Launch the application. This method is the initial entry point that should be * called by a subclass {@code public static void main(String[] args)} method. * @param args the incoming arguments * @throws Exception if the application fails to launch */ protected void launch(String[] args) throws Exception { JarFile.registerUrlProtocolHandler(); ClassLoader classLoader = createClassLoader(getClassPathArchives()); launch(args, getMainClass(), classLoader); }