tags:

views:

8579

answers:

5

Hello,

I have a Jar file, which contains other nested Jars. When I invoke the new JarFile() constructor on this file, I get an exception which says "java.util.zip.ZipException: error in opening zip file". When I manually unzip the contents of this Jar file and zip it up again, it works fine. Also, please note that this exception is seen only on websphere 6.1.0.7 and higher versions. The same thing works fine on tomcat and weblogic. Also, when I use JarInputStream instead of JarFile, I am able to read the contents of the Jar file without any exceptions. Please let me know if you have any ideas on how this can be fixed.

Thanks, Sandhya

+2  A: 

It could be related to log4j.

Do you have log4j.jar file in the websphere java classpath (as defined in the startup file) as well as the application classpath ?

If you do make sure that the log4j.jar file is in the java classpath and that it is NOT in the web-inf/lib directory of your webapp.


It can also be related with the ant version (may be not your case, but I do put it here for reference):

You have a .class file in your class path (i.e. not a directory or a .jar file). Starting with ant 1.6, ant will open the files in the classpath checking for manifest entries. This attempted opening will fail with the error "java.util.zip.ZipException"

The problem does not exist with ant 1.5 as it does not try to open the files. - so make sure that your classpath's do not contain .class files.


On a side note, did you consider having separate jars ?
You could in the manifest of your main jar, refer to the other jars with this attribute:

Class-Path: one.jar two.jar three.jar

Then, place all of your jars in the same folder.
Again, may be not valid for your case, but still there for reference.

VonC
A: 

Thanks a lot for your response.

However, I do not have a log4j.jar in the websphere Java classpath.

Please make that a comment to my answer (you can delete this answer)
VonC
+3  A: 

I've seen this exception before when whatever the JVM considers to be a temp directory is not accessible due to not being there or not having permission to write.

Artur...
A: 

Hi, i'm getting the same error java.util.zip.ZipException when trying to place hibernate.cfg.xml in classpath. any Suggestions?

upog
A: 

make sure your jar file is not corrupted.. if its corrupted or not able to unzip this error will occur..

Arul