我正在尝试将反射库包含在示例 jar 中,但无法使其正常工作:
$ kotlinc hello.kt -d hello.jar
$ java -jar hello.jar
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
缺少运行时库,所以让我们添加它:
$ 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
现在包含了运行时库,但是缺少反射库,所以让我们指定 kotlin 主目录:
$ 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
help 列出了一个 ' -no-reflect
' 选项,所以我假设在-include-runtime
设置 ' ' 时默认情况下应该包含反射库,但情况似乎并非如此。