| Author |
Read MANIFEST-MF files that are with in jars that exists in jars with in WEB-INF/lib
|
Vijay Venkat
Ranch Hand
Joined: Aug 12, 2001
Posts: 52
|
|
Hi, I want to read the contents of MANIFEST.MF file that exists in different jars in the WEB-INF/lib directory. WEB-INF lib api.jar impl.jar another.jar So api.jar, impl.jar and another.jar all have its MANIFEST.MF File ie api.jar!/META-INF/MANIFEST.MF impl.jar!/META-INF/MANIFEST.MF another.jar!/META-INF/MANIFEST.MF My requirement is to read the MANIFEST.MF file in each of the jars to derive specific information. I tried out getResource(api.jar!/META-INF/MANIFEST.MF); 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. Thanks, Vijay Venkataraman
|
 |
Vijay Venkat
Ranch Hand
Joined: Aug 12, 2001
Posts: 52
|
|
Hi I missed few information. WEB-INF lib api.jar impl.jar another.jar xyz.jar pty.jar I am interested only in MANIFEST.MF in api.jar and impl.jar. I dont want MANIFEST.MF of all the jars. Thanks, Vijay
|
 |
Vijay Venkat
Ranch Hand
Joined: Aug 12, 2001
Posts: 52
|
|
Hi, 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, Vijay Venkataraman
|
 |
James Carman
Ranch Hand
Joined: Feb 20, 2001
Posts: 580
|
|
|
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.
|
James Carman, President<br />Carman Consulting, Inc.
|
 |
Vijay Venkat
Ranch Hand
Joined: Aug 12, 2001
Posts: 52
|
|
Hi James Carman, 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. Thanks, Vijay Venkataraman
|
 |
James Carman
Ranch Hand
Joined: Feb 20, 2001
Posts: 580
|
|
|
Oops, sorry. Guess I should have read your post a little more closely. Well, I think you're doing it the right way (open up the specific jar and find the MANIFEST.MF file manually). You could still do it using getResources(), I believe. You'd just have to check each URL that's returned to make sure that it came from one of the correct jars. I haven't tested that theory yet, but I believe it will work. That way, you're letting the classloader do a lot of your work. Good luck.
|
 |
John G Bolger
Greenhorn
Joined: Apr 15, 2005
Posts: 1
|
|
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: META-INF/MANIFEST>MF META-INF/roles.xml mave/edu/role/RoleService.java Thanx a lot
|
 |
James Carman
Ranch Hand
Joined: Feb 20, 2001
Posts: 580
|
|
|
I've seen times where the leading "/" character makes a difference. Also, your roles.xml file is located in the "META-INF" directory, so the resource name would actually be "META-INF/roles.xml" or "/META-INF/roles.xml"
|
 |
 |
|
|
subject: Read MANIFEST-MF files that are with in jars that exists in jars with in WEB-INF/lib
|
|
|