Retrieving the Manifest File of the Originating JAR
To access the Manifest file of the JAR that initiated your application, conventional methods like getClass().getClassLoader().getResources(...) may not suffice, especially in environments like applets or webstart applications. Here are two alternative approaches to consider:
Iterating through Retrieved URLs:
Example Code:
Enumeration<URL> resources = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { try { URL url = resources.nextElement(); Manifest manifest = new Manifest(url.openStream()); // If manifest is null, try using JarInputStream instead: manifest = url.openStream().getManifest(); // Verify and process the manifest as needed ... } catch (IOException e) { // Handle the exception } }
Checking ClassLoader Type and Using findResource():
Example Code:
URLClassLoader cl = (URLClassLoader) getClass().getClassLoader(); try { URL url = cl.findResource("META-INF/MANIFEST.MF"); Manifest manifest = new Manifest(url.openStream()); // Do your stuff with the manifest ... } catch (IOException e) { // Handle the exception }
The above is the detailed content of How to Access the Manifest File of the Originating JAR in Applet or Webstart Environments?. For more information, please follow other related articles on the PHP Chinese website!