LoginSignup
6
12

More than 3 years have passed since last update.

Kotlinのコマンドライン実行

Last updated at Posted at 2019-08-28

install

環境

OS:windows10
​kotlinc:1.3.50 (JRE 11.0.2+9-LTS)

dowload for windows

Kotlinのコンパイラは、GitHub Repository Release 1.3.50 · JetBrains/kotlin · GitHubからZipをダウンロードする。

配置

ダウンロードしたkotlin-compiler.zipを任意のディレクトリに配置する。

Path

任意のディレクトリに配置したkotlincのbinフォルダをPathに設定する。
例:C:\Program Files\kotlinc\bin

versionの確認

> kotlinc -version
info: kotlinc-jvm 1.3.50 (JRE 11.0.2+9-LTS)

Kotlinの実行

scriptの実行

  1. Sample.ktの実装
println("Hello world!")


2. scriptのコンパイル・実行
kotlinc に -script オプションを付けることで、コンパイルの手順を飛ばして、スクリプト言語のように実行する。

kotlinc -script sample.kts
error: unable to instantiate class Sample (Sample.kts): java.lang.NoClassDefFoundError: kotlin/script/templates/standard/ScriptTemplateWithArgs

jmvコンパイル・実行

  1. Sample.ktの実装
/* entry point */
fun main(args: Array<String>) {
    println("Hello, World!")
}


2. sample,jarの生成

>kotlinc sample.kt -include-runtime -d Sample.jar


3. sample,jarの実行

>kotlin sample.jar
Hello, World!

or

>java -jar sample.jar
Hello, World!

ref

6
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
12