Compile Kotlin with coroutines via command line
See original GitHub issueSTRUCTURE:
1.Main.kt file
import kotlinx.coroutines.*
fun main(args: Array<String>) {
GlobalScope.launch { // launch a new coroutine in background and continue
delay(1000L) // non-blocking delay for 1 second (default time unit is ms)
println("World!") // print after delay
}
println("Hello,") // main thread continues while coroutine is delayed
Thread.sleep(2000L) // block main thread for 2 seconds to keep JVM alive
}
2. kotlinx-coroutines-core-1.3.0-M1.jar https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.3.0-M1
COMPILE COMMAND:
kotlinc Main.kt -cp kotlinx-coroutines-core-1.3.0-M1.jar -include-runtime -d program.jar
output: program.jar
RUN:
java -jar program.jar
EXCEPTION:
Exception in thread “main” java.lang.NoClassDefFoundError: kotlinx/coroutines/GlobalScope at MainKt.main(Main.kt:10) Caused by: java.lang.ClassNotFoundException: kotlinx.coroutines.GlobalScope at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) … 1 more
How can I fix this?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:9 (2 by maintainers)
You should also specify additional classpath libraries when you run it:
There is any way to use coroutines compiled via command line using kotlinc-js ?