I build a jar file with Intellij IDEA 2019.1.3. It's a very simple Helloworld project. But once i use java jar xxx.jar
, an error happened: Can not find or load main class
.
But i have defined main class.
Here is the content in my META-INF/MANIFEST.MF file:
Manifest-Version: 1.0
Class-Path: .
Main-Class: apk.Main
And here is my jar file structure:
-apk
--Main
-META-INF
--MANIFEST.MF
--abc.kotlin_module
My build.grale file as below:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.31'
}
group 'abc'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
jar {
manifest {
attributes (
"Class-Path": ".",
"Main-Class": "apk.Main"
)
/*from {
configurations.dependencies.collect { it.isDirectory() ? it : zipTree(it) }
}*/
}
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
It seems everything is ok in this jar. But what is wrong with my jar?