Using java invocation API from K/N

Hello. I try to call java code from native application using java invocation api. Also I want load libjvm using dlopen syscall.

interop.def
headers = jni.h
libraryPaths = /usr/lib/jvm/java-1.11.0-openjdk-amd64/lib/server

compilerOpts.linux = -I/usr/lib/jvm/java-1.11.0-openjdk-amd64/include -I/usr/lib/jvm/java-1.11.0-openjdk-amd64/include/linux
SampleLinux.kt
package sample

import interop.*
import platform.posix.*
import kotlinx.cinterop.*

typealias createVm = (CValuesRef<CPointerVar<JavaVMVar>>?, CValuesRef<COpaquePointerVar>?, CValuesRef<*>?) -> jint

fun main() {
    val dl = dlopen("/usr/lib/jvm/java-11-openjdk-amd64/lib/server/libjvm.so", RTLD_LAZY)
    if (dl != null) {
        val createVm = dlsym(dl, "JNI_CreateJavaVM")
        if (createVm != null) {
            val createVmR: CPointer<CFunction<createVm>> = createVm.reinterpret()
        }
    }
}

I’ve figured out how to properly open library and get symbol from it. But I couldn’t figure out how to create corresponding structs for passing as createVmR arguments. Help please.

Here’s my generated interop file:
interop.kt.zip (7.0 KB)

I am looking to do the same thing, and as it’s pretty much a black art I figured I would reach out :slight_smile: