Here you can find the source of getManifest(ClassLoader cl, String extension)
Parameter | Description |
---|---|
cl | A ClassLoader which should find the manifest. |
extension | The value of the 'Extension-Name' jar-manifest attribute; used to identify the manifest. |
public static Manifest getManifest(ClassLoader cl, String extension)
//package com.java2s; import java.io.IOException; import java.net.URL; import java.util.Enumeration; import java.util.jar.Attributes; import java.util.jar.Manifest; public class Main { /**//from w ww .j a v a2 s. c o m * Returns the manifest of the jar which contains the specified extension. * The provided ClassLoader is used for resource loading. * @param cl A ClassLoader which should find the manifest. * @param extension The value of the 'Extension-Name' jar-manifest attribute; used to identify the manifest. * @return the requested manifest or null when not found. */ public static Manifest getManifest(ClassLoader cl, String extension) { try { Enumeration resources = cl.getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { Manifest manifest = new Manifest(((URL) resources.nextElement()).openStream()); Attributes attributes = manifest.getMainAttributes(); if (attributes != null && extension.equals(attributes.getValue(Attributes.Name.EXTENSION_NAME))) { return manifest; } } } catch (IOException ex) { throw new RuntimeException("Unable to read manifest.", ex); } return null; } }