Java Class Loader loadManifest(Class manifestFileClass)

Here you can find the source of loadManifest(Class manifestFileClass)

Description

load Manifest

License

Apache License

Declaration

public static Manifest loadManifest(Class manifestFileClass) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.net.URL;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

public class Main {
    public static Manifest loadManifest(Class manifestFileClass) {
        try {/*from  w w w  .j a  va2s.  c  o m*/
            URL jarFileLocation = manifestFileClass.getClassLoader()
                    .getResource(manifestFileClass.getName().replace(".", "/") + ".class");
            if (jarFileLocation != null) {
                String jarFilePath = jarFileLocation.getFile();
                jarFilePath = jarFilePath.substring(0, jarFilePath.indexOf("!"));
                if (jarFilePath.startsWith("file:")) {
                    jarFilePath = jarFilePath.substring(jarFilePath.indexOf(":") + 1);
                }
                JarFile file = new JarFile(new File(jarFilePath));
                return file.getManifest();
            }
        } catch (Throwable ignored) {
        }
        return new Manifest();
    }
}

Related

  1. loadClasses(Collection filenames, String packageName, File outputDir)
  2. loadClassesImplementsTheInterface(String packageName, Class interfaceClazz)
  3. loadClassifiers(String dataDirectoryName)
  4. loadConfig(String path, ClassLoader classLoader)
  5. loadForClass(final Class clazz, final String filename)
  6. loadManifest(Class theClass)
  7. loadManifestFrom(Class c)
  8. loadProperties(final Properties properties, final String fileName, final ClassLoader cl)
  9. loadStyleSheet(Class type)