public static Manifest getManifest ( Location jarLocation ) throws IOException { URI uri = jarLocation . toURI ( ) ; // Small optimization if the location is local if ( "file" . equals ( uri . getScheme ( ) ) ) { JarFile jarFile = new JarFile ( new File ( uri ) ) ; try { return jarFile . getManifest ( ) ; } finally { jarFile . close ( ) ; } } // Otherwise, need to search it with JarInputStream JarInputStream is = new JarInputStream ( new BufferedInputStream ( jarLocation . getInputStream ( ) ) ) ; try { // This only looks at the first entry, which if is created with jar util, then it'll be there. Manifest manifest = is . getManifest ( ) ; if ( manifest != null ) { return manifest ; } // Otherwise, slow path. Need to goes through the entries JarEntry jarEntry = is . getNextJarEntry ( ) ; while ( jarEntry != null ) { if ( JarFile . MANIFEST_NAME . equals ( jarEntry . getName ( ) ) ) { return new Manifest ( is ) ; } jarEntry = is . getNextJarEntry ( ) ; } } finally { is . close ( ) ; } return null ; }
Load the manifest inside the given jar .