# 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.jar

Inference

  • The Kotlin compiler is itself written in Java and is packaged into a jar file

  • Thus java -jar /path/to/kotlin-compiler.jar is basically the kotlinc command

  • If Main.kt uses functions/ utilities from the Kotlin standard library, these dependencies have to be packaged into the compiled jar file.

  • The kotlin standard library is a part of the kotlin-runtime, hence we use the -include-runtime flag