Kotlin with OpenCV 4.10 on macOS terminal

Many things changed in Sun libs in Java 9+. Try using the JDK 8.

Still, I suppose you already installed Kotlin in your machine, you should try running it as a script like:

#!/usr/bin/env kotlinc -script

@file:DependsOn("org.openpnp:opencv:3.4.2-1")

import org.opencv.core.Core

System.loadLibrary(Core.NATIVE_LIBRARY_NAME)
println("Hello OpenCV " + Core.VERSION + "!")
println("Hello to you too, Java " + System.getProperty("java.version") + "!")

Then:

chmod +x ShowVersion.kts
./ShowVersion.kts

All the possible misconfigured classpath problems would be handled by the Kotlin compiler so if it does not work is probably the JDK version.

I had problems with the Sun XML libs in the past. When using JDK 9+ I’ve always looked up the Maven package containing the class and imported it manually in the project/script using Maven/Gradle/ecc.

Do not trust Sun libraries!

If the same error happens again add this line to the script:

@file:DependsOn("com.sun.xml.stream:sjsxp:1.0.2")