Search code examples
javajakarta-eeglassfishclassloadermanifest

Reading an EAR's manifest


I need to load the manifest of an application I am deploying on Glassfish as an EAR.

All the info I've found on internet is regarding reading manifests of jars or wars. I've tried to apply the snippets of code I've found to my problem but I've not made it. What i get is that I can have any manifest, either from the jars that my EAR contains, or even from the jars in the Glassfish domain lib folder. Not the one of the EAR.

Structure of the EAR: At root level there are some jars, one of which contains the class with the code that intends to load the EAR manifest.

ClassLoader cl = getClass().getClassLoader();
resources = cl.getResources("META-INF/MANIFEST.MF");

I've tried the getResourceAsStream method, but since that failed to give me the manifest I wanted, I tried the getResources method to see all the manifests it can give me and iterate them, taking a look at the path where they are. And none of them is the EAR manifest. I get the manifests of all the jars in my EAR, and all the lib jars in the Glassfish domain.

I've also tried casting the getClassLoader as URLClassLoader and EarClassLoader, as suggested in other StackOverFlow similar questions, seeing no difference in results.

This EAR is generated from a project in MyEclipse which has only the EAR facet. That project contains no code and just references the other projects which end up making the jars inside it.


Solution

  • You need to locate where the ear file is and then get the manifest by:

    new java.util.jar.JarFile(file).getManifest();