在JAR中打包Kotlin .kt类 [英] package Kotlin .kt class in a JAR
问题描述
如何构建 HelloWorld.kt
作为 JAR
以便它运行?
How do I build HelloWorld.kt
as a JAR
so that it runs?
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
运行时。
Note that it's declared as a class, and so the method is not on the top level(?). Would want to include the kotlin
runtime as well.
我是否需要手动创建 MANIFEST.MF
Main-Class /jar/appman.htmlrel =nofollow noreferrer>切入点?
Do I need to manually create a MANIFEST.MF
with Main-Class
for the entry point?
推荐答案
你应该使用像Gradle这样的任务构建工具。
You should use a build tool like Gradle for that task.
在这个例子中,正在创建一个带有Manifest条目的Jar: https://github.com/s1monw1/kotlin_vertx_example/blob/master/build.gradle.kts
In this example, a Jar with Manifest entry is being created: https://github.com/s1monw1/kotlin_vertx_example/blob/master/build.gradle.kts
这篇关于在JAR中打包Kotlin .kt类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!