2017-04-11 30 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爲適當的依賴關係在那裏,而不是捆綁他們的應用程序在單個罐子裏。