wave2: fix opencv dll load fail from library directory

This commit is contained in:
Andy Yang 2026-02-04 11:49:37 +08:00
parent e3fdca4ac2
commit 8e55124158
2 changed files with 18 additions and 2 deletions

View File

@ -25,7 +25,7 @@ public class SEApplication {
System.setProperty("jna.library.path", combinedPath); System.setProperty("jna.library.path", combinedPath);
// 如果 OpenCV 使用的是标准 JNI (System.loadLibrary)可能还需要设置 java.library.path // 如果 OpenCV 使用的是标准 JNI (System.loadLibrary)可能还需要设置 java.library.path
System.setProperty("java.library.path", opencvPath); System.setProperty("opencv.library.path", opencvPath);
SpringApplication.run(SEApplication.class, args); SpringApplication.run(SEApplication.class, args);
} }
} }

View File

@ -18,6 +18,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.File;
import java.net.ConnectException; import java.net.ConnectException;
import java.util.Collections; import java.util.Collections;
import java.util.UUID; import java.util.UUID;
@ -136,7 +137,22 @@ public class JmImageController {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
static { static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME); //System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
//加载 OpenCV (强制使用绝对路径加载解决 UnsatisfiedLinkError)
String openCvDll = System.getProperty("opencv.library.path") + File.separator + Core.NATIVE_LIBRARY_NAME + ".dll";
try {
File dllFile = new File(openCvDll);
if (dllFile.exists()) {
// 注意必须使用 System.load() 加载绝对路径
System.load(dllFile.getAbsolutePath());
System.out.println("SUCCESS: OpenCV loaded from -> " + dllFile.getAbsolutePath());
} else {
System.err.println("ERROR: OpenCV DLL not found at -> " + openCvDll);
}
} catch (Throwable e) {
System.err.println("CRITICAL: Failed to load OpenCV: " + e.getMessage());
e.printStackTrace();
}
} }
/*@IgnoreAuth /*@IgnoreAuth