org.springframework.boot.loader.archive.JarFileArchive Java Examples
The following examples show how to use
org.springframework.boot.loader.archive.JarFileArchive.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LancherTest.java From tac with MIT License | 6 votes |
protected final Archive createArchive() throws Exception { ProtectionDomain protectionDomain = getClass().getProtectionDomain(); CodeSource codeSource = protectionDomain.getCodeSource(); URI location = (codeSource == null ? null : codeSource.getLocation().toURI()); String path = (location == null ? null : location.getSchemeSpecificPart()); if (path == null) { throw new IllegalStateException("Unable to determine code source archive"); } File root = new File(path); if (!root.exists()) { throw new IllegalStateException( "Unable to determine code source archive from " + root); } return (root.isDirectory() ? new ExplodedArchive(root) : new JarFileArchive(root)); }
Example #2
Source File: WebApplication.java From TrackRay with GNU General Public License v3.0 | 6 votes |
protected static Archive createArchive(Class clazz) throws Exception { ProtectionDomain protectionDomain = clazz.getProtectionDomain(); CodeSource codeSource = protectionDomain.getCodeSource(); URI location = codeSource != null ? codeSource.getLocation().toURI() : null; String path = location != null ? location.getSchemeSpecificPart() : null; if (path == null) { throw new IllegalStateException("Unable to determine code source archive"); } else { File root = new File(path); if (!root.exists()) { throw new IllegalStateException("Unable to determine code source archive from " + root); } else { return (Archive)(root.isDirectory() ? new ExplodedArchive(root) : new JarFileArchive(root)); } } }
Example #3
Source File: DependencyProcessor.java From spring-cloud-formula with Apache License 2.0 | 5 votes |
public DependencyProcessor(LauncherProperties properties, DependencyResolver dependencyResolver) throws Exception { this.properties = properties; this.dependencyResolver = dependencyResolver; JarFileArchive frameworkArchive = new JarFileArchive(new File(properties.getFrameworkPath())); frameworkArchives = frameworkArchive .getNestedArchives(entry -> entry.getName().startsWith(FormulaLauncher.BOOT_INF_LIB)); }
Example #4
Source File: BootJarLaucherUtils.java From tac with MIT License | 5 votes |
/** * * @param jarFile * @param jarEntry * @return * @throws IOException */ private static Archive getUnpackedNestedArchive(JarFile jarFile, JarEntry jarEntry) throws IOException { String name = jarEntry.getName(); if (name.lastIndexOf("/") != -1) { name = name.substring(name.lastIndexOf("/") + 1); } File file = new File(getTempUnpackFolder(), name); if (!file.exists() || file.length() != jarEntry.getSize()) { unpack(jarFile, jarEntry, file); } return new JarFileArchive(file, file.toURI().toURL()); }
Example #5
Source File: LancherTest.java From tac with MIT License | 5 votes |
private Archive getUnpackedNestedArchive(JarEntry jarEntry) throws IOException { String name = jarEntry.getName(); if (name.lastIndexOf("/") != -1) { name = name.substring(name.lastIndexOf("/") + 1); } File file = new File(getTempUnpackFolder(), name); if (!file.exists() || file.length() != jarEntry.getSize()) { unpack(jarEntry, file); } return new JarFileArchive(file, file.toURI().toURL()); }
Example #6
Source File: ConfigurationMetadataDocumentationMojo.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
@Override public List<Archive> getNestedArchives(EntryFilter ignored) throws IOException { try { List<Archive> archives = new ArrayList<>(mavenProject.getRuntimeClasspathElements().size()); for (String dep : mavenProject.getRuntimeClasspathElements()) { File file = new File(dep); archives.add(file.isDirectory() ? new ExplodedArchive(file) : new JarFileArchive(file)); } return archives; } catch (DependencyResolutionRequiredException e) { throw new IOException("Could not create boot archive", e); } }
Example #7
Source File: FormulaLauncher.java From spring-cloud-formula with Apache License 2.0 | 4 votes |
public FormulaLauncher(LauncherProperties properties, DependencyProcessor dependencyProcessor) throws Exception { super(new JarFileArchive(new File(properties.getApplicationPath()))); this.dependencyProcessor = dependencyProcessor; }
Example #8
Source File: ApplicationRunner.java From liiklus with MIT License | 4 votes |
@SneakyThrows public ConfigurableApplicationContext run() { System.setProperty("plugins.dir", findPluginsDir().getAbsolutePath()); System.setProperty("plugins.pathMatcher", "*/build/libs/*.jar"); var tempFile = Files.createTempFile("app", ".jar"); tempFile.toFile().deleteOnExit(); try (var appJarStream = getClass().getClassLoader().getResourceAsStream("app-boot.jar")) { Files.copy(appJarStream, tempFile, StandardCopyOption.REPLACE_EXISTING); } var launcher = new JarLauncher(new JarFileArchive(tempFile.toFile(), tempFile.toUri().toURL())) { ClassLoader createClassLoader() throws Exception { return super.createClassLoader(getClassPathArchives()); } @Override protected ClassLoader createClassLoader(URL[] urls) throws Exception { var systemClassLoader = ClassLoader.getSystemClassLoader(); return new LaunchedURLClassLoader(urls, systemClassLoader.getParent()) { @Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { var classFile = findResource(name.replace(".", "/") + ".class"); if (classFile != null) { // If exists in the app.jar, load it from the system classloader instead log.debug("Loading class '{}' from the system ClassLoader instead", name); return systemClassLoader.loadClass(name); } return super.loadClass(name, resolve); } }; } }; var currentClassLoader = Thread.currentThread().getContextClassLoader(); try { var appClassLoader = launcher.createClassLoader(); Thread.currentThread().setContextClassLoader(appClassLoader); var applicationClass = appClassLoader.loadClass("com.github.bsideup.liiklus.Application"); var createSpringApplicationMethod = applicationClass.getDeclaredMethod("createSpringApplication", String[].class); var application = (SpringApplication) createSpringApplicationMethod.invoke(null, (Object) new String[0]); application.setDefaultProperties(properties); return application.run(); } finally { Thread.currentThread().setContextClassLoader(currentClassLoader); } }
Example #9
Source File: BootJarLoadingTest.java From karate with MIT License | 4 votes |
private static ClassLoader getJarClassLoader() throws Exception { File jar = new File("../karate-core/src/test/resources/karate-bootjar-test.jar"); assertTrue(jar.exists()); return new IntegrationTestJarLauncher(new JarFileArchive(jar)).createClassLoader(); }
Example #10
Source File: BootApplicationConfigurationMetadataResolver.java From spring-cloud-dashboard with Apache License 2.0 | 4 votes |
private Archive resolveAsArchive(Resource app) throws IOException { File moduleFile = app.getFile(); return moduleFile.isDirectory() ? new ExplodedArchive(moduleFile) : new JarFileArchive(moduleFile); }
Example #11
Source File: BootApplicationConfigurationMetadataResolver.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
private Archive resolveAsArchive(Resource app) throws IOException { File moduleFile = app.getFile(); return moduleFile.isDirectory() ? new ExplodedArchive(moduleFile) : new JarFileArchive(moduleFile); }
Example #12
Source File: DefaultValidationService.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
private static Archive resolveAsArchive(Resource app) throws IOException { Assert.notNull(app, "The resource specified for the app must not be null"); File moduleFile = app.getFile(); return moduleFile.isDirectory() ? new ExplodedArchive(moduleFile) : new JarFileArchive(moduleFile); }