“No main manifest attribute” when creating Kotlin jar using IntelliJ IDEA

前端 未结 2 1963
感动是毒
感动是毒 2020-12-07 04:00

When creating a jar from my Kotlin code and running it, it says \"No main manifest attribute\". When looking at the manifest.mf, it has this content:

Manifes         


        
相关标签:
2条回答
  • 2020-12-07 04:38

    I got this error with Gradle and Kotlin. I had to add in my build.gradle.kts an explicit manifest attribute:

    tasks.withType<Jar> {
        manifest {
            attributes["Main-Class"] = "com.example.MainKt"
        }
    }
    

    From the gradle documentation, it's better to create a fatJar task to englobe all of the runtime dependencies in case you encounter java.lang.NoClassDefFoundError errors

    0 讨论(0)
  • 2020-12-07 04:56

    If any of the dependent jars has a MANIFEST.MF file, it will override your custom one which defines the Main-Class.

    In order to address this problem you should do the following:

    • Disable the alphabetical ordering
    • Change items ordering so that item which has META-INF/MANIFEST.MF file is the first in the list
    • Your custom MANIFEST.MF will be picked up by IntelliJ IDEA and displayed for the jar artifact.

    See the related issue for more details.

    You can also use Gradle or Maven to generate the fat jar instead.

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