[How to Solve] Error: Invalid or corrupt jarfile…

After using IDEA to create a quickstart project through MAVEN and adding Artifacts, it was found that the generated jar package could not be run, and the following error occurred:

Error: Invalid or corrupt jarfile D:\WorkSpace\JavaStudy\*\out\artifacts\*_jar\*.jar

So I tried a lot of methods first, and found that there is no META_INF folder in the jar package at all through comparison, which is the root cause of the jar’s inability to run;

Solutions:

Make sure your MANIFEST.MF is  in : 
src /main/resources/META_INF/ 

NOT 
src /main/java/META_INF/


Problem Analysis:
IDEA, when adding artifacts in File\Project Structure\Artifacts\, the default will be to create a directory under src/main/java/META_INF/, but this directory (src/main/java/) has been marked as Sources Root, compile only.
So you should cut src/main/java/META_INF to src/main/resources/META_INF/, src/main/resources/ is Resources Root and will copy to the out directory

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *