I want to read the contents of MANIFEST.MF file that exists in different jars in the WEB-INF/lib directory.
So api.jar, impl.jar and another.jar all have its MANIFEST.MF File
My requirement is to read the MANIFEST.MF file in each of the jars to derive specific information.
I tried out
I always get a null. I am kind of stuck trying to figure this out. Can anyone let me know the correct usage or point to relevant documents? Any help is highly appreciated.
I found a way to get to the Jar files in WEB-INF/lib using
String path = ServletContext.getRealPath(WEB-INF/lib/[myJarName])
Create a Jar URL stream using this path. And then get to the manifest to look for information.
If any one knows of a better way of doing it, kindly let me know.
Thanks for your helping hand on this issue. I had done that. But my requirement was to pick the MANIFEST.MF file from a specific jar. say B.jar in the path rather than making my class loader look for all the files by that name. I am not sure what is the cost of doing something like that.
If anyone know's how expensive it is - Kindly let me know.
I really appreciate the time taken from your end to respond. So what i am doing is something like this i know there is a class by name a.b.c.X.class.
Use X.class.getClassLoader().getResource(a/b/c/X.class). With this i know from which Jar file my class is being picked up
The url would be some thing like /somedirve/.../TheJar.jar!/a/b/c/X.class.
Then do url.getFile()
Remove the extra path from theJar.jar and create a new inputStream to the Jar file TheJar.jar and create a JarInputStream and then read the manifest file using the jar api's.
Check the API for ClassLoader. There's a method called getResources( String name ) that you can use for exactly this purpose. It will return all of the resources on the classpath by that name as an Enumeration of URL objects. We do this in HiveMind to locate all of the module descriptor files (resource path is /META-INF/hivemodule.xml). It works beautifully.
HI James, can u help me out here, im trying to load an xml config file from a jar, which is not a servlet. and im just running into probs here getting the error "ImputStream cannot be null".
Your post seems to fit the solution to my prob.
Any chance of u posting a few lines of code to get the file from the jar?
What im using:
InputStream xmlStream = RoleService.class.getResourceAsStream(ROLES_FILE_NAME);
where ROLES_FILE_NAME = "/roles.xml"
and jar structure is:
Thanx a lot