Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting a JAR manifest file using Perl

Status
Not open for further replies.

MrKappaChi

Programmer
Aug 15, 2002
4
US
In my perl script I'm attempting to extract a JAR manifest file. The Manifest.mf file is created whenever you create a jar file. I'm using the manifest to store Implementation-Version, and I want to access that in my perl script. My problem is that the Manifest.mf file is in a subdirectory META-INF (META-INF/MANIFEST.MF). I'm able to extract any files from the main directory, but am unable to extract any file from any subdirectory. My code looks like this:
@args = ("jar", "xf", "test.jar", "META-INF/MANIFEST.MF");
system(@args);

when I print the command out it looks like:
jar xf test.jar META-INF/MANIFEST.MF

and if I just paste that into the shell , it works fine, just not from within the perl script. I know it's not that particular subdirectory that won't work because I've tried it with several files in subdirectories and none work. Anybody know how it would be possible to extract files from within subdirectories of a jar file? Thank you in advance.
 
it may be a simple problem...try running this:

@args = ("jar", "xf", "test.jar", "META-INF/MANIFEST.MF");
print @args;
#system(@args);

What looks like may be happening is you're not allowing for any spaces between the elements in the array when doing the system command. Try the above code and see what printing the array actually looks like.
 
I alread tried that the command is:
jar xf test.jar META-INF/MANIFEST.MF

And then I tried copying the command exactly as it was printed and then pasted it in the Unix command and it worked. I just won't work from within the perl script. And it's not just that subdirectory, I can't extract files from any subdirectories. I works fine when I try to extract a file from the main directory.
 
Why do you need to specify the manifest file when extracting? I thought that the manifest was only used when creating a new jar file. And when you use the manifest, don't you need to use the -m switch as well?

jaa
 
I'm still wondering if it's a 'space' problem. It may be that when it's PRINTED to the screen it has spaces, but it may not have spaces in the system command. Just for giggles, try this: (it can't hurt to try!)!

@args = ("jar\s", "xf\s", "test.jar\s", "META-INF/MANIFEST.MF");
system(@args);

I'm SURE you did this, but make sure to cwd() to the main directory before running the system() command!
 
I'm using the Manifest to specify the Specification-Version and the Implementation-Version of the utility that is JAR'ed. When the user uses the update program it has to check to see if they have the current version of the utility installed, if not it will update the newer components. So I want to extract the manifest only, as a file, to check these versions. You only need the -m switch when updating the jar and you with to merge the current jar manifest with an updated jar manifest, not when extracting it. I'm able to accomplish what I want by extracting the entire jar and finding the manifest, but that is very unnecessary if I can just extract the manifest. I don't know what the problem is, but I was wondering if it is with specifying a directory path as a parameter. (Which doesn't seem like it should be a problem).
 
Ok everybody, I'm sorry, I figured it out. It was a VERY stupid mistake. I've been working on this for hours and I couldn't see the whole time that I had:
system($args)
instead of:
system(@args)

I can't believe it. Sorry bout that, and thanks a lot for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top