Error: Invalid or corrupt jar file
Hello.
I am trying to create a jar file.
After finishing my project, I went to “File” → “Project Structure”. Then I went to the "Artifacts" tab. On the second lane, I pressed the plus symbol. Chose “Add” → JAR → “From modules with dependencies”. Then I chose my main class and clicked ok. I also clicked "ok" in the Project Structure window. Then, I went to “Build” → “Build Artifacts…” and in the “Build Artifact” menu that appeared, I chose “Build”.
The .jar was created and it worked fine. However, later on I made some changes in the project and wanted to make a new version of the .jar file. I deleted the old one. Then I went to “Build” → “Build Artifacts…” and in the “Build Artifact” menu that appeared, I chose “Build”. I tried to open the .jar file and it prompted me with an error message:

I guessed that the error was due to the fact that I chose “Build” and not “Rebuild” (without deleting the old one) here:

So I did the following:
- Went to “File” → “Project Structure” and in the “Artifacts” tab, I deleted the old artifact and created a new one.
Then went to “Build” → “Build Artifacts…” and in the “Build Artifact” menu that appeared, I chose “Build”. Didn't work. - Went to “Build” → “Build Artifacts…” and in the “Build Artifact” menu that appeared, I chose “Rebuild”. Didn't work.
- Went to “Build” → “Build Artifacts…” and in the “Build Artifact” menu that appeared, I chose “Clean”, then went back again and chose “Build”. Didn't work.
- Went to “Build” and tried the "Build” → “Build Project” and "Build” → “Rebuild Project” before going to “Build Artifacts…” and build/rebuild again. Didn't work.
- Completely deleted the “/out” and “src/META-INF” directories and creating them again from the “Project Structure” menu. Then “Build” → “Build Artifacts…” and build again.
I am out of ideas. My .jar file keeps giving me the error message shown above.
Any help would be appreciated.
Thanks in advance!
请先登录再写评论。
Hi, please try to
1. remove the artifacts from Project Structure
2. remove the generated jar file, and remove the out folder
3. back up and remove /.idea folder and /<project-name>.iml file.
After that, please go to File | New | Project from existing sources to import the current project and rebuild index files. Then add artifacts and build again.
Thank you for the reply.
This worked!
However, I was wondering what is the proper way to rebuild a new .jar file
If I fix my code further and want to build another, newer, version of a .jar file, what steps should I follow?