List of usage examples for org.springframework.boot.loader.archive Archive getManifest
Manifest getManifest() throws IOException;
From source file:com.hurence.logisland.classloading.PluginLoader.java
/** * Scan for plugins.//from w w w. j a v a 2s . c o m */ private static void scanAndRegisterPlugins() { Set<URL> urls = new HashSet<>(); ClassLoader cl = Thread.currentThread().getContextClassLoader(); while (cl != null) { if (cl instanceof URLClassLoader) { urls.addAll(Arrays.asList(((URLClassLoader) cl).getURLs())); cl = cl.getParent(); } } for (URL url : urls) { try { Archive archive = null; try { archive = new JarFileArchive( new File(URLDecoder.decode(url.getFile(), Charset.defaultCharset().name())), url); } catch (Exception e) { //silently swallowing exception. just skip the archive since not an archive } if (archive == null) { continue; } Manifest manifest = archive.getManifest(); if (manifest != null) { String exportedPlugins = manifest.getMainAttributes() .getValue(ManifestAttributes.MODULE_EXPORTS); if (exportedPlugins != null) { String version = StringUtils.defaultIfEmpty( manifest.getMainAttributes().getValue(ManifestAttributes.MODULE_VERSION), "UNKNOWN"); logger.info("Loading components from module {}", archive.getUrl().toExternalForm()); final Archive arc = archive; if (StringUtils.isNotBlank(exportedPlugins)) { Arrays.stream(exportedPlugins.split(",")).map(String::trim).forEach(s -> { if (registry.putIfAbsent(s, PluginClassloaderBuilder.build(arc)) == null) { logger.info("Registered component '{}' version '{}'", s, version); } }); } } } } catch (Exception e) { logger.error("Unable to load components from " + url.toExternalForm(), e); } } }
From source file:org.springframework.cloud.deployer.thin.ThinJarAppWrapper.java
protected String getMainClass(Archive archive) { try {/*from w w w .ja va 2 s . com*/ Manifest manifest = archive.getManifest(); String mainClass = null; if (manifest != null) { mainClass = manifest.getMainAttributes().getValue("Start-Class"); } if (mainClass == null) { throw new IllegalStateException("No 'Start-Class' manifest entry specified in " + this); } return mainClass; } catch (Exception e) { try { File root = new File(archive.getUrl().toURI()); if (archive instanceof ExplodedArchive) { return MainClassFinder.findSingleMainClass(root); } else { return MainClassFinder.findSingleMainClass(new JarFile(root), "/"); } } catch (Exception ex) { throw new IllegalStateException("Cannot find main class", e); } } }