title: UnsatisfiedLinkError: How to load native library of opencv when running play application?
body: <p>I am running a play framework application using opencv with scala. When I run the application I am receiving an <strong>UnsatisfiedLinkError</strong> from VideoCapture, so how can I load the opencv library correctly?</p>
  
  <p>When i run a test using classes from opencv everything works correctly. I always set the System.loadLibrary(Core.NATIVE_LIBRARY_NAME) and define the java.path.library param correctly. But when I run the play application this doesn't work as with the tests.</p>
  
  <p>From other posts, people have been resolving this issue using the abstract GlobalSetting class from play and loading the library in the beforeStart() method. But this has been deprecated and now Play recommends to do an eager binding. I have already tried to create an Eager loader to run first when I start the server where I load the library in the same way I run the tests. The code in this class run first as it's supposed to be but it doesn't save my problem.</p>
  
  <p>I have also tried to load the library in the different controllers i have and the class where I use the VideoCapture() but nothing works. Moreover, i tried to create a sbt task where i loaded the library but didn't work.</p>
  
  <pre class="lang-scala prettyprint-override"><code>class EagerLoaderModule extends AbstractModule {
    override def configure(): Unit = bind(classOf[StartUpService]).asEagerSingleton()
  }
  </code></pre>
  
  <pre class="lang-scala prettyprint-override"><code>final class StartUpService {
  
    def loadedLibs: Seq[String] = {
      val libs = classOf[ClassLoader].getDeclaredField("loadedLibraryNames")
      libs.setAccessible(true)
      import scala.collection.JavaConverters._
      libs.get(ClassLoader.getSystemClassLoader)
        .asInstanceOf[java.util.Vector[String]]
        .asScala
    }
  
    def loadOpenCVOnDemand(): Unit = {
      val isLoaded = loadedLibs.map(str =&gt; str contains "opencv").reduce((x, y) =&gt; x || y)
      if(!isLoaded) {
        try {
          println("hey there dude")
          System.loadLibrary(Core.NATIVE_LIBRARY_NAME)
          println("ksdfjsdkfh")
        } catch {
          case e: UnsatisfiedLinkError =&gt;
            println("Loading Library OPENCV")
            System.loadLibrary("opencv_java345")
          //      e.printStackTrace()
        }
      }
    }
  
    loadOpenCVOnDemand()
  
  }
  </code></pre>
  
  <p>The error I am receiving is: <strong>java.lang.UnsatisfiedLinkError: org.opencv.videoio.VideoCapture.VideoCapture_1(Ljava/lang/String;)J</strong> and I know that it is because the System.loadLibrary(Core.NATIVE_LIBRARY_NAME) isn't working correctly but how can I make it to work or where should I set it so the application loads the library correctly?</p>