包在一个JAR中的Kotlin .kt类
如何构建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$
请注意,它被声明为一个类,所以该方法不在顶层(?)。 也想包括kotlin
运行时。
我需要手动创建一个MANIFEST.MF
Main-Class
作为入口点吗?
你应该使用像Gradle这样的构建工具来完成这个任务。
在这个例子中,正在创建一个包含Manifest条目的Jar: https : //github.com/s1monw1/kotlin_vertx_example/blob/master/build.gradle.kts