java IntelliJ Maven“错误:无效或损坏的 jarfile”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32654152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 20:34:14  来源:igfitidea点击:

IntelliJ Maven "Error: Invalid or corrupt jarfile"

javamavenintellij-idea

提问by BullyWiiPlaza

I'm using IntelliJto develop JavaDesktop applications. On my project, I added framework support for Mavenand added a dependency to the pom.xmlfile. I also added a build artifact like described here(I would also appreciate if this question gets answered). Now that my project has Mavensupport, the generated JARfile no longer works. When I try to launch it, it displays the error Error: Invalid or corrupt jarfile MyProject.jar. When I open the JARfile using WinRAR, there is no MANIFEST.MFfile included, only folders and CLASSfiles. What happened to my Mavendependencies as well? Why does IntelliJnot properly build my Mavenproject into an executable JARfile via its artifacts?

我正在使用IntelliJ开发Java桌面应用程序。在我的项目中,我为文件Maven添加了框架支持并添加了依赖项pom.xml。我还添加了一个像这里描述的构建工件(如果这个问题得到回答,我也会很感激)。现在我的项目得到Maven支持,生成的JAR文件不再有效。当我尝试启动它时,它显示错误Error: Invalid or corrupt jarfile MyProject.jar。当我使用打开JAR文件时WinRAR,没有MANIFEST.MF包含文件,只有文件夹和CLASS文件。我的Maven依赖项也发生了什么?为什么不能通过其工件IntelliJ将我的Maven项目正确构建到可执行JAR文件中?

回答by Marian Klühspies

  1. Go to Module Settings--> Artifacts
  2. Create a new folder called META-INFenter image description here
  3. Add the MANIFESTfile which should be located in your src folder enter image description here
  1. 转到模块设置-->工件
  2. 创建一个名为META-INF的新文件夹在此处输入图片说明
  3. 添加应位于 src 文件夹中的MANIFEST文件 在此处输入图片说明

as a file

作为文件

enter image description here

在此处输入图片说明

This will tell IntelliJ to copy the manifest into the jar file.

这将告诉 IntelliJ 将清单复制到 jar 文件中。