Creating Jar with Intellij 2016 - No main manifest attribute

后端 未结 10 1987
清歌不尽
清歌不尽 2021-01-30 16:03

I am getting no main manifest attribute while running the jar create by Intellij. I extracted the jar and observed that there was another manifest

10条回答
  •  名媛妹妹
    2021-01-30 16:33

    Putting the META-INF folder in */resources can do, but is not the way: Intellij just puts all under main/resources or test/resources in the root level of the generated jar, that's why it works; but in a Java project, we usually put them under project root, which is the same level as src. Putting them under "resources" is breaking the convention, besides, they are not resource files.

    Make sure you:

    • use the existent MANIFEST.MF file at project root;
    • the main class is correct
    • ticked the Include in Project build under "Project structure" -> "Artifacts" panel
    • have META-INF folder listed in the files to include in the jar, apart from "project compiled output", in the Output Layout tab
    • the generated file type is JAR, at right top corner

    And then, save the settings, build again, and enter "Build" menu to "Build Artifacts..", and "build" the JAR. Check the generated jar again, run with java -jar.

提交回复
热议问题