OpenCV 4.1.0 in Linux: works with Java but not with Kotlin

asked 2019-05-21 11:32:00 -0500

Moso gravatar image

I’m trying to stay as simple (less tools) as possible, working only at command line with vi and a few files.

import org.opencv.core.Core;

public class ShowVersions {

  static {

  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

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...


import org.opencv.core.Core

fun main(args: Array<String>) {
  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(
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(
        at java.base/java.lang.ClassLoader.loadClass(
        ... 1 more

:( What do I need to do to get this simple test code to work in Kotlin as easy as was in Java?

edit retag flag offensive close merge delete