我只是想理解底层架构,我想我弄错了.
Taking the tutorial here as the example.
当我这么做的时候:
kotlinc-jvm hello.kt -include-runtime -d hello.jar
如果编译器已经将代码转换为Java字节码,为什么需要将Kotlin运行时Bundle 到jar中?
我只是想理解底层架构,我想我弄错了.
Taking the tutorial here as the example.
当我这么做的时候:
kotlinc-jvm hello.kt -include-runtime -d hello.jar
如果编译器已经将代码转换为Java字节码,为什么需要将Kotlin运行时Bundle 到jar中?
当您用Java编写应用程序时,您将依赖于所有标准类库.这java.
个班(例如java.lang.*
、java.util.*
.)都包含在每个JRE中,所以您不需要自己打包它们.
Kotlin包含自己的标准类库(Kotlin runtime),与Java类库分开.要分发任何人都可以使用普通的旧JRE运行的jar文件,还需要Bundle Kotlin运行时.
如果您没有Bundle Kotlin运行时,那么在执行应用程序时,您的用户必须确保Kotlin运行时位于类路径上.您链接的页面提供了此方案的示例:
编辑图书馆
If you’re developing a library to be used by other Kotlin applications, you can produce the .jar file without including the Kotlin runtime into it.
$ kotlinc-jvm hello.kt -d hello.jar
如果您针对的是其他Kotlin用户,那么可以合理地假设他们已经拥有了Kotlin运行时.但是,如果您试图为最终用户部署应用程序,那么您希望包含Kotlin运行时,以便应用程序是自包含的.