I am new to Kotlin and trying to learn asynchronous programming using coroutine. I am following Kotlin official docs. But when I tried to compile my code, it showed me error: "unresolved reference: kotlinx". So I just want to know, how can I use Coroutine in non android projects?
I am using Ubuntu terminal to compile the code.
Code Snippet
import kotlinx.coroutines.*
fun main(args: Array<String>){
GlobalScope.launch{
delay(1000L)
println("World!")
}
println("Hello,")
Thread.sleep(2000L)
}
Download kotlinx-coroutines-core-1.2.1.jar, put it into the same folder where the source file (Example.kt
) is, and compile it:
kotlinc Example.kt -cp kotlinx-coroutines-core-1.2.1.jar -include-runtime -d Example.jar
Run Example.jar
using command
java -cp kotlinx-coroutines-core-1.2.1.jar:Example.jar ExampleKt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With