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:
Manifest-Version: 1.0
When looking at the file in the source, it has this content:
Manifest-Version: 1.0
Main-Class: MyMainClass
When manually copying the source manifest to the jar, it runs perfectly.
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
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:
META-INF/MANIFEST.MF
file is the first in the listMANIFEST.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.
1.Add the following task definition in the build script
tasks.jar {
manifest {
attributes["Main-Class"] = "MainKt"
}
configurations["compileClasspath"].forEach { file: File ->
from(zipTree(file.absoluteFile))
}
}
For Spring boot apps:
What worked for me (gradle kotlin) in build.gradle.kts
plugins {
id("org.springframework.boot") version "2.6.7"
}
apply(plugin = "io.spring.dependency-management")
springBoot {
mainClass.set("com.example.Application")
}
Found this all by reading up on spring-boot docs found here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.