Kotlin 1.4.21 - where is kotlin-runtime.jar

Just making first step into Kotlin. Running on Win10 with Java 8.
Tried the CL compiler - downloaded and unzipped kotlin-compiler-1.4.21.zip from GitHub.
Added ‘kotlinc\bin’ to path. Compiler creates .class file and I can run ‘kotlin HelloKt’.
But not ‘java HelloKt’ - getting ‘java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics’
OK so online tutorial says need ‘kotlin-runtime.jar’ in classpath.
Except that there is no such JAR in ‘lib’ folder.
I can run this:
java -cp .;D:\work\kotlinc\lib\kotlin-runner.jar HelloKt
but that is different JAR.
Any ideas?

You should include kotlin-stdlib.jar in the classpath for java. It should be in the lib directory.
You can also pass the -include-runtime argument to kotlinc, this will instruct it to merge the standard library jar in the resulting jar file.

What tutorial do you use by the way? Is it from kotlinlang.org? Probably it’s out of date and should be actualized.

2 Likes

Thanks for reply - I was following Hadi Hariri’s “Introduction To Kotlin Programming” on O’Reilly’s website. It is very likely somewhat out of date since since it was published in 2016. His IntelliJ examples cannot be followed verbatim either since UI changed.

1 Like

Sorry, still can’t configure build properly: what should be included where?
I added extra dependencies:

dependencies {
    implementation(kotlin("stdlib-jdk8"))
    implementation("org.jetbrains.kotlin:kotlin-stdlib")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-common")

And tried different sources:

    jar {
        manifest.attributes["Main-Class"] = "MainKt"

        duplicatesStrategy = DuplicatesStrategy.INCLUDE
        from("compileKotlin").outputs
//        val dependencies = configurations.runtimeClasspath.get().map(::zipTree)
//        from(dependencies)
//        from(getByName("compileKotlin"))
//        from(
//            configurations.runtimeClasspath.get().map {
//                it.takeIf { it.isDirectory } ?: zipTree(it)
//            }
//        )

And even added a .jar lib into build/libs/kotlin-stdlib-jdk8-1.8.21.jar (but it is deleted after gradle clean, so it doesn’t belong there, so I put it into lib also).
And still I have the error:

java -jar kapp-1.0-SNAPSHOT.jar 
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
        at MainKt.main(main.kt)

How should I configure my build.gradle.kts properly? I use kotlinOptions.jvmTarget = "17"

The current problem became to found the main class, created another topic