0

Am new to this forum.Need your help on understanding how we can update a zip file in a URL.

We have a zip file which can be accessed with a URL.Eg http://domainname/filename.zip

I would need to update the contents in the filename.zip,i can see the filename.zip on the application server under the following directory Eg:/stage/iam_im/iam_im.ear/user_console.war/app/filename.zip

It is a Java based application and its deployed on a weblogic Server,I just want to know,is it possible i can go directly to the file location and update the filename.zip or being a war file,should i do some packaging which am not sure of.

Thanks in Advance, Antony

Antony
  • 9
  • 2
  • The best option would be to rebuild the application from source. If that is not possible you can try modifying the war file, see for example http://stackoverflow.com/questions/19269961/how-to-unpackage-and-repackage-a-war-file If you just overwrite the zip your change will be lost when the app server redeploys the war – rve Mar 02 '16 at 14:41
  • your question is a bit unclear: do you need to programatically update the contents of the zip or do you need to repack the war file with a new zip? – rve Mar 04 '16 at 07:19
  • Thanks for the responses,am not looking programattically,as you said ,I just want to repack the war file with my new version of zip file – Antony Jul 11 '16 at 08:39

1 Answers1

-1

This is an example to to copy another file into an existing zip using java.nio.file.FileSystem together with Files.copy(). It 'mounts' the zip using the ZipFileSystem Provider. Then you can just copy whatever you want into it. The changes seem to take place on fs.close()

public static void main(String[] argv) {
Path myFilePath = Paths.get("c:/dump2/mytextfile.txt");

Path zipFilePath = Paths.get("c:/dump2/myarchive.zip");
try( FileSystem fs = FileSystems.newFileSystem(zipFilePath, null) ){
    Path fileInsideZipPath = fs.getPath("/mytextfile.txt");
    Files.copy(myFilePath, fileInsideZipPath);
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

}

You could as well use it to first get out the file you want to change and replace it in the 'mount' after you're done.

Akunosh
  • 237
  • 1
  • 2
  • 10