Creating Jar with Intellij 2016 - No main manifest attribute

后端 未结 10 1709
清歌不尽
清歌不尽 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:44

    In IntelliJ Idea 2020

    Follow the instructions in this video.

    When you get to the Artifact creation point (Ctrl + Shift + Alt + S) change the location of the manifest as shown here. (\src\main\resources)

    0 讨论(0)
  • 2021-01-30 16:48

    In my case I had some dependencies added in my jar, which itself generated a Manifest. I didn't get it to work straight out of Intellij. However, what you can do is open the jar file with a zip program and add the Main class yourself and then copy it back into the jar:

    0 讨论(0)
  • 2021-01-30 16:51

    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

    0 讨论(0)
  • 2021-01-30 16:53

    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).

    0 讨论(0)
提交回复
热议问题