我如何构建HelloWorld.kt
as a 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
with Main-Class
为了入口点 https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html?
您应该使用 Gradle 之类的构建工具来完成该任务。
在此示例中,正在创建一个包含 Manifest 条目的 Jar:https://github.com/s1monw1/kotlin_vertx_example/blob/master/build.gradle.kts https://github.com/s1monw1/kotlin_vertx_example/blob/master/build.gradle.kts
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)