[英]Running Spring boot with Opencv on Elastic Beanstalk
I have a Spring boot application packaged as WAR which uses OpenCV for some image processing and I would like to run it on Elastic Beanstalk (Tomcat environment). 我有一个打包为WAR的Spring引导应用程序,它使用OpenCV进行某些图像处理,我想在Elastic Beanstalk(Tomcat环境)上运行它。 Is there a way how to package it with the native Opencv libraries? 有没有办法将其与本机Opencv库打包?
Everything is working fine on my local machine where I have the following configuration: 在具有以下配置的本地计算机上,一切工作正常:
opencv_310.jar
placed in src/webapp/WEB-INF/lib
opencv_310.jar
放在src/webapp/WEB-INF/lib
path/to/opencv/build/bin
) 将Opencv添加到Java构建路径( path/to/opencv/build/bin
) -Djava.library.path=path/to/opencv/opencv/build/lib
使用VM参数-Djava.library.path=path/to/opencv/opencv/build/lib
运行的Tomcat This setup works fine and I am even able to package it with maven clean pakcage
. 这个设置工作正常,我什至可以用maven clean pakcage
。
However, if I want to deploy to Amazon Elastic Beanstalk, I just cannot assume that Opencv will be installed on that machine (it won't) so I need to somehow package it inside my WAR file so everything is self-contained. 但是,如果我想部署到Amazon Elastic Beanstalk,我只是不能假定Opencv将安装在该机器上(不会安装),因此我需要以某种方式将其打包到WAR文件中,以便所有内容都是独立的。
When I deploy my WAR to ELB, I always get 将WAR部署到ELB时,我总是得到
java.lang.UnsatisfiedLinkError: no opencv_java300 in java.library.path
when loading Opencv with System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
使用System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
加载System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
I found some tutorials on this for archaic versions of Opencv but I cannot seem to figure out how to do this easily. 我找到了一些有关Opencv的原始版本的教程,但似乎无法弄清楚如何轻松地做到这一点。 I would be glad for any tips, because I have been stuck on this for a long time. 我会为任何提示而高兴,因为我已经坚持了很长时间。
When you run your tomcat server, you could pass the path to native libraries, so they will be preloaded, like this: 运行tomcat服务器时,可以将路径传递给本机库,这样它们将被预加载,如下所示:
java -Djava.library.path=...
other way would be to put the libraries into the folder where the main jar (jar that you run tomcat from) of tomcat is. 另一种方法是将库放入tomcat的主jar(运行tomcat的jar)所在的文件夹中。
I solved the problem by using this excellent Github project which provides OpenCV Java bindings packaged with native libraries and provided as a Maven dependency. 我通过使用这个出色的Github项目解决了这个问题,该项目提供了与本机库一起打包并作为Maven依赖项提供的OpenCV Java绑定。
There is also a newer fork of this project with more up-to-date version of OpenCV which I am probably going to switch to. 这个项目也有一个较新的分支 ,其中包含我可能会改用的最新版本的OpenCV。 It supports OpenCV 2.4.10 which is a step back from version 3.1 that I was using but it does everything I expected from it. 它支持OpenCV 2.4.10,这是我使用的3.1版本的一个后退步骤,但它可以完成我期望的一切。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.