error invalid or corrupt jarfile что делать

Corrupt jar file

I have created a jar file in windows 7 using eclipse. When I am trying to open the jar file it says invalid or corrupt jar file. Can anyone suggest me why the jar file is invalid?

12 Answers 12

In Eclispe, you need to export the project as Runnable JAR file instead of as JAR file to get a real executable JAR.

This regularly occurs when you change the extension on the JAR for ZIP, extract the zip content and make some modifications on files such as changing the MANIFEST.MF file which is a very common case, many times Eclipse doesn’t generate the MANIFEST file as we want, or maybe we would like to modify the CLASS-PATH or the MAIN-CLASS values of it.

The problem occurs when you zip back the folder.

A valid Runnable/Executable JAR has the next structure:

Once you’re done try execute it on the command line using:

When you use a zip tool to unpack, change files and zip again, normally the JAR structure changes to this structure which is incorrect, since another directory level is added on the top of the file system making it a corrupted file as is shown below:

The problem might be that there are more than 65536 files in your JAR: Why java complains about jar files with lots of entries? The fix is described in this question’s answer.

This is the common issue with «manifest» in the error? Yes it happens a lot, here’s a link: http://dev-answers.blogspot.com/2006/07/invalid-or-corrupt-jarfile.html

Using the ant task to create the manifest file on-the-fly gives you and entry like:

Читайте также:  Что значит холщовый мешочек

Creating the manifest file myself, with the bare essentials fixes the issue:

Notes:

Parsing of the Meta-inf file has been an issue that has come-up, been fixed and then come-up again for sun. See: Bug Id: 4991229. If you can work out if this bug exists in the your (or my) version of the Java SE you have more patience that me.

Also, make sure that the java version used at runtime is an equivalent or later version than the java used during compilation

As I just came across this topic I wanted to share the reason and solution why I got the message «invalid or corrupt jarfile»:

I had updated the version of the «maven-jar-plugin» in my pom.xml from 2.1 to 3.1.2. Everything still went fine and a jar file was built. But somehow it obviously wouldn’t run anymore.

As soon as i set the «maven-jar-plugin» version back to 2.1 again, the problem was gone.

It can be a typo int the MANIFEST.MF too, p.ex. Build-Date with two :

If the jar file has any extra bytes at the end, explorers like 7-Zip can open it, but it will be treated as corrupt. I use an online upload system that automatically adds a single extra LF character (‘\n’, 0x0a) to the end of every jar file. With such files, there are a variety solutions to run the file:

Источник

Сказочный портал