简体   繁体   English

执行jar时intellij中的“没有主要清单属性”错误

[英]“no main manifest attribute” error in intellij when executing jar

I'm working on a kotlin project that I want to execute as a jar.我正在处理一个我想作为 jar 执行的 kotlin 项目。 This is all done in IntelliJ Idea and I went about making the jar using the artifacts.这一切都是在 IntelliJ Idea 中完成的,我开始使用工件制作罐子。

The process I followed was (as illustrated by an Idea guide):我遵循的过程是(如创意指南所示):

  1. Add artifact (as jar) from project structure从项目结构中添加工件(作为 jar)
  2. Build jar构建罐子
  3. Run jar运行罐子

After this, I get a在此之后,我得到一个

'no main manifest attribute, in ____.jar'

What I have tried after reading several stack overflow questions:在阅读了几个堆栈溢出问题后,我尝试了什么:

  • Checking that the manifest file is in the correct folder and has the correct path in the artifact检查清单文件是否在正确的文件夹中并且在工件中具有正确的路径
  • Adding code to the build.gradle file for the jar->manifest portion将代码添加到 jar->manifest 部分的 build.gradle 文件
  • Trying the method of moving the manifest stuff into a resources folder尝试将清单内容移动到资源文件夹的方法
  • Checking that the jar exists检查 jar 是否存在
  • Moving the manifest stuff into a different folder (java,kotlin,out folders)将清单内容移动到不同的文件夹(java、kotlin、out 文件夹)
  • Making sure that the manifest file is in the correct format确保清单文件的格式正确

All of the above has not worked.以上所有都没有奏效。

Something that is confusing to me is that, even when I alter the manifest file to be in "incorrect" format, it still gives the same error.让我感到困惑的是,即使我将清单文件更改为“不正确”的格式,它仍然会出现相同的错误。 The path stated in the artifact's details is correct yet there is no difference even when I purposely input incorrect items in the manifest file.工件详细信息中所述的路径是正确的,但即使我故意在清单文件中输入不正确的项目,也没有区别。 Not sure if that is the"real" problem but I'm also not sure how to fix that as well不确定这是否是“真正的”问题,但我也不知道如何解决这个问题

For anyone that may have encountered this problem in intellij and did not find a solution in any other posts, what helped me was对于可能在 intellij 中遇到过这个问题并且在任何其他帖子中没有找到解决方案的人,对我有帮助的是

  1. Navigating to Project Structure导航到项目结构
  2. Going to the Artifacts tab转到工件选项卡
  3. Explicitly adding a new META-INF/ directory in my jar在我的 jar 中显式添加一个新的 META-INF/ 目录
  4. Adding the created MANIFEST.MF file to the META-INF/ in the jar FROM THE ARTIFACTS TAB从工件选项卡将创建的 MANIFEST.MF 文件添加到 jar 中的 META-INF/
  5. Rearranging the order for the META-INF/ to be at the top重新排列 META-INF/ 的顺序,使其位于顶部
  6. Building and running构建和运行

The end result looked like this最终结果是这样的

None of the solutions worked for me.没有一个解决方案对我有用。

I solved it in this way:我是这样解决的:
When setting up the artifact, change:设置工件时,更改:
Meta-inf: (...)\\src\\main\\ (you must remove " java ") Meta-inf: (...)\\src\\main\\ (你必须删除“ java ”)

Also, there was a problem with resources, solved this way:另外,资源有问题,解决方法如下:
When setting up the artifact:设置工件时:
Output Layout > Add copy of > Directory content > resources .输出布局 > 添加副本 > 目录内容 > 资源

That's all!仅此而已!

在创建可执行的 jar 文件时,显式地创建一个 mainfest.txt 文件,该文件应该按照目录结构的顺序,mainfest.txt 文件应该只包含一行(Main-Class:包含 main 方法的类的名称)然后运行 ​​jar 工具

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM