Search code examples
kotlinjarjvmide

How to compile .kt files to .jar files without an editor


I am trying to write my own IDE and I'm trying to figure out how to compile Kotlin files to Jar files without using another program to do it for me. Is there a way I can do this? I've tried looking through the InteliJ source code to figure out how it works, but to no avail. If possible, is there a way to compile .kt files to .jar files in cmd?


Solution

  • You can do this with the kotlinc command. You can simply use the -d option to specify the output jar or directory. For example,

    kotlinc sourceFile1.kt sourceFile2.kt -include-runtime -d output.jar
    java -jar output.jar