Here you can find the source of getManifestValue(File jarFile, String key)
Parameter | Description |
---|---|
jarFile | jar file |
key | name of attribute we are looking for |
Parameter | Description |
---|---|
IOException | an exception |
public static String getManifestValue(File jarFile, String key) throws IOException
//package com.java2s; //License from project: LGPL import java.io.File; import java.io.IOException; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; public class Main { /**// ww w . j a va2 s . c om * Gets main attribute value from jar manifest * * @param jarFile * jar file * @param key * name of attribute we are looking for * @return * value of the attribute, null if not found * @throws IOException */ public static String getManifestValue(File jarFile, String key) throws IOException { JarFile jF = null; try { jF = new JarFile(jarFile); Manifest mf = jF.getManifest(); return mf.getMainAttributes().getValue(key); } finally { if (jF != null) { jF.close(); } } } /** * Gets all main attributes of jar manifest * * @param jarFile * @return * @throws IOException */ private static Attributes getMainAttributes(File jarFile) throws IOException { JarFile jF = null; try { jF = new JarFile(jarFile); Manifest mf = jF.getManifest(); return mf.getMainAttributes(); } finally { if (jF != null) { jF.close(); } } } }