Creating Jar with Intellij 2016 - No main manifest attribute

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.

enter image description here


If using Maven, Ensure your pom.xml has the main class referenced and fully qualified, similar to:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>org.mypkg.MyMainClass</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

(... of course the version number of the plugin may be different).

The main class being not fully qualified, is what leads people to suggest moving the manifest to another location (in order to satisfy the reference locally).


I spent a few days to resolve it. My solution: I loaded a project that present in this answer. Then I compared and corrected settings of the loaded project and my own project. I compared/corrected:

  • Run/Debug Configurations
  • MANIFEST.MF
  • in Progect Structure settings: Project, Modules (mark what is sources, resources and etc), Artifacts.

In the end, I placed META-INF in resources directory.

Maybe i did excess actions, but it worked for me :)

P.S. also need to choose "Inherit project compile output path" in Progect Structure settings -> Modules -> Path

enter image description here


I was stucked with the same problem with maven build. When you are creating the artifact from project structure settings (ctrl+alt+shift+S), you have to change manifest directory:

<project folder>\src\main\java 

change java to resources

<project folder>\src\main\resources

I have also used the option extract to the target JAR, and it's working well.

EDIT

You can find a detailed step-by-step, an other solutions here: https://stackoverflow.com/a/45303637/2640826