我正在尝试生成一个具有以下特征的docker镜像
*SO--> ubuntu:18.04
*Java--> openjdk-11-jdk
*OpenCV--> 3.4.2版本
我能够成功地生成图像,但在lib文件夹中没有生成java 342文件,我得到了这个异常:java.library.path中没有opencv_java342
我正在使用以下命令作为入口点启动我的应用:
java -Djava.library.path=/var/lib/opencv-3.4.2/build/lib -jar Application.jar
字符串
日志输出
Constructor threw exception; nested exception is java.lang.UnsatisfiedLinkError: no opencv_java342 in java.library.path: [/var/lib/opencv-3.4.2/build/lib]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1303) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1197) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
at com.etaluma.oem.controller.camera.CameraServerApplication.main(CameraServerApplication.java:11) ~[classes!/:0.8.11-SNAPSHOT]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47) ~[CameraServerSimulator.jar:0.8.11-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:86) ~[CameraServerSimulator.jar:0.8.11-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) ~[CameraServerSimulator.jar:0.8.11-SNAPSHOT]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) ~[CameraServerSimulator.jar:0.8.11-SNAPSHOT]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.etaluma.oem.controller.camera.CameraServerImpl]: Constructor threw exception; nested exception is java.lang.UnsatisfiedLinkError: no opencv_java342 in java.library.path: [/var/lib/opencv-3.4.2/build/lib]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:184) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1295) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
... 24 common frames omitted
Caused by: java.lang.UnsatisfiedLinkError: no opencv_java342 in java.library.path: [/var/lib/opencv-3.4.2/build/lib]
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2660) ~[na:na]
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:829) ~[na:na]
at java.base/java.lang.System.loadLibrary(System.java:1867) ~[na:na]
at com.etaluma.oem.controller.camera.CameraServerImpl.<init>(CameraServerImpl.java:24) ~[classes!/:0.8.11-SNAPSHOT]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
... 26 common frames omitted
型
Docker文件
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y ant
RUN apt-get install -y openjdk-11-jdk
ARG JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
ENV JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
RUN echo $JAVA_HOME
RUN apt-get install -y wget
RUN apt-get install -y cmake
RUN apt-get install -y g++
RUN apt-get install -y unzip
RUN apt-get install -y vim
RUN java -version
RUN wget https://github.com/opencv/opencv/archive/3.4.2.zip
RUN unzip 3.4.2.zip -d /var/lib/
RUN mkdir /var/lib/opencv-3.4.2/build
WORKDIR /var/lib/opencv-3.4.2/build
RUN cmake -DBUILD_SHARED_LIBS=OFF ..
RUN make -j8
型
Docker文件系统x1c 0d1x
OpenCV编译过程中的一般配置
-- General configuration for OpenCV 3.4.2 =====================================
-- Version control: unknown
--
-- Platform:
-- Timestamp: 2019-10-07T00:32:28Z
-- Host: Linux 4.9.184-linuxkit x86_64
-- CMake: 3.10.2
-- CMake generator: Unix Makefiles
-- CMake build tool: /usr/bin/make
-- Configuration: Release
--
-- CPU/HW features:
-- Baseline: SSE SSE2 SSE3
-- requested: SSE3
-- Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
-- requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
-- SSE4_1 (3 files): + SSSE3 SSE4_1
-- SSE4_2 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2
-- FP16 (2 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
-- AVX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
-- AVX2 (9 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
-- AVX512_SKX (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_SKX
--
-- C/C++:
-- Built as dynamic libs?: NO
-- C++11: YES
-- C++ Compiler: /usr/bin/c++ (ver 7.4.0)
-- C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
-- C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
-- C Compiler: /usr/bin/cc
-- C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -Wimplicit-fallthrough=3 -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
-- C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -Wimplicit-fallthrough=3 -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
-- Linker flags (Release):
-- Linker flags (Debug):
-- ccache: NO
-- Precompiled headers: YES
-- Extra dependencies: dl m pthread rt
-- 3rdparty dependencies: ittnotify libprotobuf zlib libjpeg-turbo libwebp libpng libtiff libjasper IlmImf ippiw ippicv
--
-- OpenCV modules:
-- To be built: calib3d core dnn features2d flann highgui imgcodecs imgproc java_bindings_generator ml objdetect photo python_bindings_generator shape stitching superres ts video videoio videostab
-- Disabled: js world
-- Disabled by dependency: -
-- Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java python2 python3 viz
-- Applications: tests perf_tests apps
-- Documentation: NO
-- Non-free algorithms: NO
--
-- GUI:
-- GTK+: NO
-- VTK support: NO
--
-- Media I/O:
-- ZLib: build (ver 1.2.11)
-- JPEG: libjpeg-turbo (ver 1.5.3-62)
-- WEBP: build (ver encoder: 0x020e)
-- PNG: build (ver 1.6.34)
-- TIFF: build (ver 42 - 4.0.9)
-- JPEG 2000: build (ver 1.900.1)
-- OpenEXR: build (ver 1.7.1)
-- HDR: YES
-- SUNRASTER: YES
-- PXM: YES
--
-- Video I/O:
-- DC1394: NO
-- FFMPEG: NO
-- avcodec: NO
-- avformat: NO
-- avutil: NO
-- swscale: NO
-- avresample: NO
-- GStreamer: NO
-- libv4l/libv4l2: NO
-- v4l/v4l2: linux/videodev2.h
-- gPhoto2: NO
--
-- Parallel framework: pthreads
--
-- Trace: YES (with Intel ITT)
--
-- Other third-party libraries:
-- Intel IPP: 2017.0.3 [2017.0.3]
-- at: /var/lib/opencv-3.4.2/build/3rdparty/ippicv/ippicv_lnx
-- Intel IPP IW: sources (2017.0.3)
-- at: /var/lib/opencv-3.4.2/build/3rdparty/ippicv/ippiw_lnx
-- Lapack: NO
-- Eigen: NO
-- Custom HAL: NO
-- Protobuf: build (3.5.1)
--
-- OpenCL: YES (no extra features)
-- Include path: /var/lib/opencv-3.4.2/3rdparty/include/opencl/1.2
-- Link libraries: Dynamic load
--
-- Python (for build): NO
--
-- Java:
-- ant: /usr/bin/ant (ver 1.10.5)
-- JNI: /usr/lib/jvm/java-11-openjdk-amd64/include /usr/lib/jvm/java-11-openjdk-amd64/include/linux /usr/lib/jvm/java-11-openjdk-amd64/include
-- Java wrappers: NO
-- Java tests: NO
--
-- Matlab: NO
--
-- Install to: /usr/local
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /var/lib/opencv-3.4.2/build
型
所以我想知道我是否在docker文件或openCV编译过程中遗漏了一些东西。
注意:如果我在本机中执行相同的进程,一切都按预期工作
有什么建议吗
3条答案
按热度按时间8fsztsew1#
将
libopencv_java342.so
文件从/usr/local/lib
复制到/usr/lib
。如果未生成
.so
文件,请尝试以下操作:字符串
myss37ts2#
我有一个类似的问题,我注意到从你的职位两件事是失踪
1.在OpenCV编译过程文件的“OpenCV模块:待建:“我没有看到Java。根据官方文档,java必须存在。
检查CMake的输出,确保java是“待构建”的模块之一。如果没有,很可能你缺少了依赖性。
1.我在你的Dockerfile中没有看到Python,你需要它。这是官方文件中提到的要求。
为了使用Java绑定构建OpenCV,您需要安装JDK(Java开发工具包)(我们建议Oracle/Sun JDK 6或7),Apache Ant和Python v2.6或更高版本。
我用了这句台词
字符串
奇怪的是,当我添加python时,java被包含在“要构建的OpenCV模块”中
kfgdxczn3#
用Java打开CV 4.8
opencvlibs
目录中。如果您在Debian linux上部署,请将opencvlibs
的内容复制到libs
目录。然后,Linux将按照约定找到它们运行Java:
java.library.path
指定.soDocker文件:
字符串