Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Kotlinc coroutine in non android project?

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)
 }
like image 281
karan sharma Avatar asked Oct 16 '22 14:10

karan sharma


1 Answers

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
like image 165
atarasenko Avatar answered Oct 18 '22 04:10

atarasenko