Including reflection library in jar issue using kotlink

I am trying to get the reflection lib included in the sample jar but cannot get it to work:

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

      

The lib executable is missing, so add it:

$ 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

      

Now the lib executable is included, but the reflection lib is missing, so let's specify the kotlin home directory:

$ 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

      

Reflection lib is still not included. kotlinc

help specifies the ' -no-reflect

' option , so I am assuming the reflection library should be enabled by default when " -include-runtime

" is set, but that doesn't seem to be the case.

+3


source to share


1 answer


Currently the option -include-runtime

only includes the Kotlin standard library ( kotlin-stdlib

) in the resulting jar. You are correct that the reflection library ( kotlin-reflect

) should also be included if no option is specified -no-reflect

. I created an issue in the tracker: https://youtrack.jetbrains.com/issue/KT-17344

Until the problem is resolved: If you are looking for a way to run the compiled program only on your computer, I recommend that you compile your application into a directory instead of a jar, and then run the main class with kotlin

.



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

      

If you plan to distribute the program to other users, I recommend using the correct build system like Maven or Gradle, and listing kotlin-stdlib

/ kotlin-reflect

as the correct dependencies there, rather than bundling them together with your application in one jar.

+5


source







All Articles