LinuxCommandLibrary

kotlin

Compile and run Kotlin code

TLDR

Run a jar file

$ kotlin [filename.jar]
copy

Display Kotlin and JVM version
$ kotlin -version
copy

SYNOPSIS

kotlin [options] argument [program_arguments...]
kotlin --version
kotlin --help

PARAMETERS

.kts_script
    Path to a Kotlin script file (.kts) to be executed directly. Example: kotlin myscript.kts.

-jar jar_file
    Executes a program encapsulated in a JAR file. The JAR must have a main class specified in its manifest. Example: kotlin -jar myapp.jar.

-classpath path / -cp path
    Specifies the user class path for loading classes and resources. The path can be a directory, an archive (JAR/ZIP file), or a list of such paths separated by the system's path separator. Example: kotlin -cp myclasses com.example.MyMainClass.

-Dproperty=value
    Sets a system property for the JVM process. This is useful for passing configuration values to your Kotlin application. Example: kotlin -Dmy.setting=true myscript.kts.

--version
    Prints the Kotlin runtime version information and exits.

--help
    Displays a synopsis of the standard options and usage information for the kotlin command.

[program_arguments...]
    Any arguments following the main command or script/JAR file are passed directly to the Kotlin program or script as command-line arguments.

DESCRIPTION

The kotlin command is an essential part of the Kotlin toolchain, primarily used for executing compiled Kotlin applications (JAR files) or direct Kotlin scripts (.kts files) on the Java Virtual Machine (JVM). It acts as a convenient wrapper over the underlying java command, handling the necessary classpath setup for Kotlin runtime libraries.

While its sibling command, kotlinc, is responsible for compiling Kotlin source code, kotlin focuses on runtime execution. It's crucial for developers who need to quickly test scripts, run standalone applications, or integrate Kotlin execution into shell scripts and build automation workflows.

CAVEATS

The kotlin command fundamentally relies on a Java Runtime Environment (JRE) being installed and accessible on the system, as Kotlin primarily targets the JVM.

The executable itself is often a shell script that invokes the java command with the necessary Kotlin runtime libraries on its classpath.

Its exact behavior and available options might vary slightly depending on how Kotlin is installed (e.g., via SDKMAN, official distribution, or OS package manager).

Copied to clipboard