Java Jar File Find getJarManifest(File file)

Here you can find the source of getJarManifest(File file)

Description

get Jar Manifest

License

Open Source License

Declaration

public static Manifest getJarManifest(File file) throws IOException 

Method Source Code


//package com.java2s;
/*// ww w.j  ava  2s.c o  m
 * Copyright (c) 2006-2012 Nuxeo SA (http://nuxeo.com/) and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Nuxeo - initial API and implementation
 *
 * $Id$
 */

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

public class Main {
    public static Manifest getJarManifest(File file) throws IOException {
        JarFile jar = null;
        try {
            jar = new JarFile(file);
            return jar.getManifest();
        } finally {
            if (jar != null) {
                jar.close();
            }
        }
    }

    public static Manifest getManifest(File file) {
        try {
            if (file.isDirectory()) {
                return getDirectoryManifest(file);
            } else {
                return getJarManifest(file);
            }
        } catch (IOException ignored) {
            return null;
        }
    }

    public static Manifest getManifest(URL url) {
        try {
            return new JarFile(new File(url.getFile())).getManifest();
        } catch (IOException e) {
            return null;
        }
    }

    public static Manifest getDirectoryManifest(File file) throws IOException {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(new File(file, "META-INF/MANIFEST.MF"));
            return new Manifest(fis);
        } finally {
            if (fis != null) {
                fis.close();
            }
        }
    }
}

Related

  1. getJarFolder(Class clazz)
  2. getJarLocation()
  3. getJarLocation(Class classFromJar)
  4. getJarLocation(Class clazz)
  5. getJarLocation(final Class cClass)
  6. getJarOrDir(Class mainClass)
  7. getJarPath(Class caller)
  8. getJarPath(String pkg)
  9. getJarPathOf(Class classObject)