• Post Reply Bookmark Topic Watch Topic
  • New Topic

Command to update a file that's inside a directory inside a .jar file?  RSS feed

 
Jeffrey Foster
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a .jar file containing this:



and an exploded copy of it next to it in the same directory, then when I do this command to add a folder and a file:



it works, the result is that the .jar file now contains this:



And when I do this, to update the file on the first level inside it:



it works also, the result is that file.jsp is updated with the edits I made in file.jsp in my exploded copy.

However, if I want to update file1.jsp, and I do this:



it doesn't seem to work.

file1.jsp is not updated in that case.

So from the first command I know that it works with directories as well as files, and from the second, I know that I can update existing files.

However what I can't seem to do is update existing files if they're not on the first level. Is that correct? Can anyone explain how to do this?

It doesn't work by the way to expand the .jar file and then zip it up again. Any time I've tried it that way, using various jar commands or compression tools, the .jar archive doesn't function anymore in the .war I'm putting it. The only way it's ever worked for me is to insert and update files using the commands above. I just don't know how to do it when the file I want to update is down a level.

Thanks very much for any advice,
 
Chris Janicki
Greenhorn
Posts: 23
Mac OS X Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what's wrong, but you might try adding the 'v' (verbose) option to the command line to see if anything useful is printed.

Also, my hunch at why unzipping/re-jarring doesn't work is because of the manifest. Unless you include the 'm' option to include the old manifest, it would create a new manifest from scratch. That's not necessarily bad, but your original manifest may contain extra properties that your app needs, but a fresh jar doesn't include. (For example, executable jars add extra properties that the jar command-line tool wouldn't include on its own.) You might try comparing (diff'ing) the original and regenerated MANIFEST.MF files to see if there are indeed differences.
 
Jeffrey Foster
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a million, the manifest was definitely the problem, I had sort of read about it but didn't understand what it meant, but yours made it easier for me to understand.

So I can now expand, edit, and re-jar these bundles successfully which just made my life a lot easier. I'll try the v command to see what was wrong with the update command at some point but for these I don't need to do it that way anymore.

I had to play around to get the command right so for any beginners out there like me, the command that worked is:

Navigate inside the expanded jar_file.jar directory (jar_file), which has the manifest inside it in a directory named META-INF, then type:

jar -cvfm jar_file.jar META-INF/MANIFEST.MF *

and it creates jar_file.jar inside the expanded one with the old manifest intact. I'm not adding any files, just updating existing ones. Now jar_file.jar is recognized and functions as it's supposed to.

Thanks again,

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!