将 Kotlin .kt class 打包到 JAR 中

package Kotlin .kt class in a JAR

如何将 HelloWorld.kt 构建为 JAR 以便它运行?

thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ kotlinc HelloWorld.kt --include-runtime -d HelloWorld.jar
error: invalid argument: --include-runtime
info: use -help for more information
thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ kotlinc HelloWorld.kt -d HelloWorld.jar
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.intellij.util.text.StringFactory to constructor java.lang.String(char[],boolean)
WARNING: Please consider reporting this to the maintainers of com.intellij.util.text.StringFactory
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ java -jar HelloWorld.jar 
no main manifest attribute, in HelloWorld.jar
thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ cat HelloWorld.kt 
import kotlin.jvm.JvmStatic

object HelloWorld {
    @JvmStatic
    public fun main(args: Array<String>) {
        println("Hello, world!" + args[0])
    }
}
thufir@dur:~/kotlin$ 

请注意,它被声明为 class,因此该方法不在顶层(?)。还想包括 kotlin 运行时。

我是否需要为 entry point 手动创建 MANIFEST.MFMain-Class

您应该使用像 Gradle 这样的构建工具来完成该任务。

在此示例中,正在创建一个包含清单条目的 Jar:https://github.com/s1monw1/kotlin_vertx_example/blob/master/build.gradle.kts