Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java Zip doesn't work when making WAR!

807603Sep 26 2007 — edited Nov 5 2007
I have written code to zip up an exploded war directory. I deploy the war in Tomcat (and websphere) and it fails with the error;
SEVERE: Exception fixing docBase: {0}
java.io.FileNotFoundException: C:\Docucorp\Tomcat\webapps\testccm\dmg\calendar.htm (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
...................

I can use Winzip, WinRar or Windows File explorer to open the war file (as a *.zip file) just fine and explode it to a directory. All the files exist and I can view them just fine. When I use winzip or windows compression utility to zip up the WAR files I just unzipped and deploy it in Tomcat it works! What in the hell is going on?!?! Its the same files, winzip can open it but tomcat can't? The files are ok when I explode them?!
Here is the code;

ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipName));
zipDir(warDirName, zos);
zos.close();
......
public static void zipDir(String dir2zip, ZipOutputStream zos)
{
try
{
File zipDirectory = new File(dir2zip);
String[] dirList = zipDirectory.list();
byte[] readBuffer = new byte[2048];
int bytesIn = 0;
for (int i = 0; i < dirList.length; i++)
{
File f = new File(zipDirectory, dirList);
if (f.isDirectory())
{
String filePath = f.getPath();
zipDir(filePath, zos);
continue;
}
FileInputStream fis = new FileInputStream(f);
ZipEntry anEntry = new ZipEntry(f.getPath().substring(f.getPath().indexOf(File.separatorChar)+1 ));
zos.putNextEntry(anEntry);
while ((bytesIn = fis.read(readBuffer)) != -1)
{
zos.write(readBuffer, 0, bytesIn);
}
fis.close();
}
} catch (Exception ex)
{
ex.printStackTrace();
}
}

Thanks,
Michael Lee
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 3 2007
Added on Sep 26 2007
17 comments
680 views