You can do one of two things:
-
Call
getResources()
and iterate through the returned collection of URLs, reading them as manifests until you find yours:Enumeration<URL> resources = getClass().getClassLoader() .getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { try { Manifest manifest = new Manifest(resources.nextElement().openStream()); // check that this is your manifest and do what you need or get the next one ... } catch (IOException E) { // handle } }
-
You can try checking whether
getClass().getClassLoader()
is an instance ofjava.net.URLClassLoader
. Majority of Sun classloaders are, includingAppletClassLoader
.
You can then cast it and callfindResource()
which has been known – for applets, at least – to return the needed manifest directly:URLClassLoader cl = (URLClassLoader) getClass().getClassLoader(); try { URL url = cl.findResource("META-INF/MANIFEST.MF"); Manifest manifest = new Manifest(url.openStream()); // do stuff with it ... } catch (IOException E) { // handle }