Java Class Loader getManifest(ClassLoader cl, String extension)

Here you can find the source of getManifest(ClassLoader cl, String extension)

Description

Returns the manifest of the jar which contains the specified extension.

License

Open Source License

Parameter

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.

Return

the requested manifest or null when not found.

Declaration

public static Manifest getManifest(ClassLoader cl, String extension) 

Method Source Code


//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;
    }
}

Related

  1. getCustomClassloader(List entries)
  2. getFileFromClassLoader(String fileName)
  3. getFilesByPackgeName(String packageName, File _file, ClassLoader classLoader, List list)
  4. getJvmExtClassLoader()
  5. getLoadingDir(Class clazz)
  6. getPackageFolder(String packageName, ClassLoader classLoader)
  7. getParentClassLoader()
  8. getProjectClassLoader(IJavaProject javaProject)
  9. getProjectClassLoader(IJavaProject javaProject, ClassLoader parentClassLoader)