# compile the kotlin code to a jar file
java -jar /opt/homebrew/opt/kotlin/libexec/lib/kotlin-compiler.jar -include-runtime src/main/kotlin/Main.kt -d hello.jar
# execute the jar file
java -jar hello.jarInference
-
The Kotlin compiler is itself written in Java and is packaged into a
jarfile -
Thus
java -jar /path/to/kotlin-compiler.jaris basically thekotlinccommand -
If
Main.ktuses functions/ utilities from the Kotlin standard library, these dependencies have to be packaged into the compiledjarfile. -
The kotlin standard library is a part of the kotlin-runtime, hence we use the
-include-runtimeflag