当前位置:网站首页>Windows uses commands to run kotlin

Windows uses commands to run kotlin

2022-07-05 09:49:00 hnjcxy

Official statement :Kotlin command-line compiler | Kotlin

1、 download  kotlin-compiler-1.6.10.zip tool kit , And extract it to an English directory without spaces , Address :Release Kotlin 1.6.10 · JetBrains/kotlin · GitHubhttps://github.com/JetBrains/kotlin/releases/tag/v1.6.10

2、 add to Kotlin environment variable , similar Java How to set environment variables , Find path, Add a message that points to the extracted in the previous step kotlin In the toolkit bin Catalog .

3、 open cmd Command window , View version input :

E:\lins\kotlin\kotlin4>kotlin -version
Kotlin version 1.6.10-release-923 (JRE 1.8.0_291-b10)

4、 newly build hello.kt The source code file , Content :

fun main() {
    println("Hello, World!")
}

5、 Compile command ( take hello.kt Translate it into hello.jar)

(1)jar Package contains kotlin The way of runtime ( compile application when ):kotlinc hello.kt -include-runtime -d hello.jar

(2)jar The package does not contain kotlin The way of runtime ( For example, compile library For others applications Invocation time ):kotlinc hello.kt -d hello.jar

6、 Run the command

(1) Run compilation mode (1) Of jar:java -jar hello.jar

(2) Run compilation mode (2) Of jar:kotlin -classpath hello.jar HelloKt

among HelloKt yes hello.jar in , primary kotlin The code is compiled into HelloKt.class The file ,HelloKt is the main class name.

7、 Other commands

kotlin -help

kotlinc -help

8、 compile class file

(1) compile :kotlinc hello.kt

function :kotlin HelloKt

原网站

版权声明
本文为[hnjcxy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140536039246.html