2017-04-11 82 views
2

我试图让包含在样品瓶反射LIB在一个罐子输出反射库,但不能得到它的工作:包括kotlinc

$ kotlinc hello.kt -d hello.jar 
$ java -jar hello.jar 
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics 

运行时的lib已丢失,因此让我们来添加:

$ kotlinc hello.kt -include-runtime -d hello.jar 
$ java -jar hello.jar 
Exception in thread "main" kotlin.jvm.KotlinReflectionNotSupportedError: Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath 

现在,运行时的lib包括,但反射LIB丢失,所以让我们指定科特林主目录:

$ kotlinc hello.kt -include-runtime -kotlin-home ~/.sdkman/candidates/kotlin/1.1.1 -d hello.jar 
$ java -jar hello.jar 
Exception in thread "main" kotlin.jvm.KotlinReflectionNotSupportedError: Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath 

反射库仍不包括在内。 kotlinc帮助列出了“-no-reflect”选项,所以我假设反射库应该由默认的“-include-runtime”时,包括设置,但是这似乎并不如此。

回答

5

目前-include-runtime选项仅包括标准科特林库(kotlin-stdlib)到所得的广口瓶中。你是在反射库(kotlin-reflect)的权利也应包括在内,除非指定了-no-reflect选项。我在跟踪器中创建了一个问题:https://youtrack.jetbrains.com/issue/KT-17344

直到问题解决:如果您正在寻找一种方法在您的机器上运行编译的程序,我建议您将应用程序编译到目录然后使用kotlin命令运行主类。

kotlinc hello.kt -d output 
kotlin -cp output hello.HelloKt 

如果您打算,虽然分发程序向其他用户,我建议一起使用适当的编译系统像Maven的或摇篮,并指定kotlin-stdlib/kotlin-reflect为适当的依赖关系在那里,而不是捆绑他们的应用程序在单个罐子里。