OpenCV 4.1.0 in Linux: works with Java but not with Kotlin
I’m trying to stay as simple (less tools) as possible, working only at command line with vi and a few files.
ShowVersions.java
import org.opencv.core.Core;
public class ShowVersions {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public static void main(String[] args) {
System.out.println("Hello OpenCV " + Core.VERSION + "!");
System.out.println("Hello to you too, Java " + System.getProperty("java.version") + "!");
}
}
Compiled with:
javac -cp /usr/share/java/opencv4/opencv-410.jar ShowVersions.java
Executed with:
java -Djava.library.path=/usr/lib -cp /usr/share/java/opencv4/opencv-410.jar:. ShowVersions
The output:
Hello OpenCV 4.1.0!
Hello to you too, Java 12.0.1!
But, trying with Kotlin...
ShowVersions.kt
import org.opencv.core.Core
fun main(args: Array<String>) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME)
println("Hello OpenCV " + Core.VERSION + "!")
println("Hello to you too, Java " + System.getProperty("java.version") + "!")
}
Compiled with:
kotlinc ShowVersions.kt -classpath /usr/share/java/opencv4/opencv-410.jar -include-runtime -d ShowVersions.jar
Executed with:
java -Djava.library.path=/usr/lib -cp /usr/share/java/opencv4/opencv-410.jar:. -jar ShowVersions.jar
No sucess...
Exception in thread "main" java.lang.NoClassDefFoundError: org/opencv/core/Core
at ShowVersionsKt.main(ShowVersions.kt:5)
Caused by: java.lang.ClassNotFoundException: org.opencv.core.Core
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
:( What do I need to do to get this simple test code to work in Kotlin as easy as was in Java?