I have an executable jar that needs to be able to tell if a file is located inside of itself. What would be a good way to go about this. Right now I am getting an enumeration of jar entries and placing its entries into an arrayList. I am then searching the arrayList for the file. Is there a more efficient way? Thanks,
Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
Mark Herschberg
Sheriff
Joined: Dec 04, 2000
Posts: 6037
posted
0
Well, you could probably search the manifest, if you can trust the manifest to be accurate. This is probably faster then having to access every file for the enumeration--but I'm only guessing here based on general file IO access. --Mark
Ivor Horton
Author
Ranch Hand
Joined: Mar 22, 2002
Posts: 67
posted
0
Hi Jason, Sounds like a good approach to me. The alternative would be to process the manifest from the jar looking for name entries, but in general not all files have to be in the manifest.
Ivor Horton<br />Author of the Beginning Java Series including the new <a href="http://www.amazon.com/exec/obidos/ASIN/1861005695/ref=ase_electricporkchop" target="_blank" rel="nofollow">Beginning Java 2 SDK 1.4 Edition</a>
Jason Kretzer
Ranch Hand
Joined: May 31, 2001
Posts: 280
posted
0
Hmmmm. I extracted all the files from the jar manually to look at the mainfest. It only had two lines. The "Main-Class" line and the "version" line that I wrote in there when I created it. Should there be others? If there should be, is it done automatically or do you have to do it manually? Thanks,
Ivor Horton
Author
Ranch Hand
Joined: Mar 22, 2002
Posts: 67
posted
0
The default manifest for an executable jar just contains what you saw. A default manifest for a non-executable jar just contains one line specifying the version number. You can add other stuff to the manifest though, either when you create the jar (using cmf option) or once the jar has been created(using umf option). You create a separate text file contain the entries you want to add(file name moreStuff say) then execute: jar umf moreStuff MyOldJar.jar In the moreStuff text file you can put file names as: Name: ThisClass.class Name: ThatClass.class Name: MyData.txt Name: MyNoisesOff.au You should then be able to extract the file names from the manifest. It's a lot of fiddling about though. Unless it's a big archive you might as well do what you are doing.
Jason Kretzer
Ranch Hand
Joined: May 31, 2001
Posts: 280
posted
0
Well, its not a very large archive as far as number of files go. There are only about 50 or so files. Thanks for your help and I really like you 1.3 version of the book. It was/is a great help.