How to import Java packages in Kotlin Native

Viewed 5973

I'm trying to import Java package for use in Kotlin native as below;

/* main.kt */
import java.util.*

fun main(args: Array<String>) {
    print("Simple program")
}

and compile it with the below command

kotlinc main.kt -o main

I got the error message

main.kt:2:8: error: unresolved reference: java
import java.util.*

obviously I need to show kotlinc where to find java.util, how can I achieve this without using the command line? I'm on Windows 10 64 bit using Kotlin native 0.3.

2 Answers

Since we can't actually add JVM-Libs to Kotlin/Native, as zsmb13 already explained, i'd like to point at GraalVM (for those who get here and do not already know about it).

https://www.graalvm.org/examples/java-kotlin-aot/

Their approach allows to use java-libs with Kotlin, because it compiles the required lib- and the JVM-classes into the native executable.

Related