UnsatisfiedLinkError with OpenCV in Tomcat

前端 未结 2 1468
醉酒成梦
醉酒成梦 2021-01-15 14:49

First of all, I have a basic example of OpenCV running in a main method. However, if I use OpenCV in a Spring Web Controller, an error is thrown.

I am getting an Uns

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-15 14:52

    It turns out that the default run configuration to start a Tomcat server within STS/Eclipse is essentially just a launcher for Tomcat. This means that any VM Args that are added to the Tomcat 'run configuration' will not be transferred to the actual Tomcat instance.

    On looking in tcruntime-instance.bat within the Tomcat directory (this is what ends up creating the tomcat java instance), we can see that simply by adding our intended VM Args to the JAVA_OPTS environment variable, the dlls will be available to Tomcat.

    TL;DR:

    So.. Simply add the the locations of the OpenCV binaries to your JAVA_OPTS environment variable:

    -Djava.library.path="C:\opencv\build\java\x64;C:\opencv\build\x64\vc10\bin"

    For more information on setting JAVA_OPTS for Tomcat, see this SO question.

提交回复
热议问题