如何将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
运行时。我需要手动为entry point创建一个带有
MANIFEST.MF
的Main-Class
吗?
最佳答案
您应该为该任务使用诸如Gradle之类的构建工具。
在此示例中,将创建一个带有 list 的Jar条目:https://github.com/s1monw1/kotlin_vertx_example/blob/master/build.gradle.kts
关于jar - 在JAR中将Kotlin .kt类打包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46979678/