Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
package com.njcn.advance.utils;
|
package com.njcn.advance.utils;
|
||||||
|
|
||||||
import cn.hutool.core.io.resource.ClassPathResource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
import java.net.URLDecoder;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pqs
|
* pqs
|
||||||
@@ -20,21 +20,20 @@ public class JnaCallDllOrSo {
|
|||||||
|
|
||||||
public JnaCallDllOrSo(String name) {
|
public JnaCallDllOrSo(String name) {
|
||||||
super();
|
super();
|
||||||
String suffix = ".dll";
|
|
||||||
try {
|
try {
|
||||||
String os = System.getProperty("os.name");
|
String os = System.getProperty("os.name");
|
||||||
// windows操作系统为1 否则为0
|
|
||||||
int beginIndex = os != null && os.startsWith("Windows") ? 1 : 0;
|
int beginIndex = os != null && os.startsWith("Windows") ? 1 : 0;
|
||||||
String nameDll;
|
String nameDll;
|
||||||
if (beginIndex == 0) {
|
if (beginIndex == 0) {
|
||||||
//linux操作系统
|
nameDll = "lib" + name + ".so";
|
||||||
nameDll = "lib" + name + "_dll";
|
|
||||||
suffix = ".so";
|
|
||||||
} else {
|
} else {
|
||||||
nameDll = name;
|
nameDll = name;
|
||||||
|
if (!name.endsWith(".dll")) {
|
||||||
|
nameDll = name + ".dll";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String tem = "/usr/local/dllFile/"+ nameDll.concat(suffix);
|
String tem = "/usr/local/dllFile/"+ nameDll;
|
||||||
File dockerFile = new File(tem);
|
File dockerFile = new File(tem);
|
||||||
if(!dockerFile.exists()){
|
if(!dockerFile.exists()){
|
||||||
boolean f = dockerFile.getParentFile().mkdirs();
|
boolean f = dockerFile.getParentFile().mkdirs();
|
||||||
@@ -42,7 +41,11 @@ public class JnaCallDllOrSo {
|
|||||||
System.out.println("文件夹创建:"+f);
|
System.out.println("文件夹创建:"+f);
|
||||||
System.out.println("文件创建:"+d);
|
System.out.println("文件创建:"+d);
|
||||||
|
|
||||||
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(nameDll.concat(suffix))) {
|
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(nameDll)) {
|
||||||
|
if (inputStream == null) {
|
||||||
|
log.error("找不到资源文件: {}", nameDll);
|
||||||
|
throw new FileNotFoundException("找不到资源文件: " + nameDll);
|
||||||
|
}
|
||||||
try (FileOutputStream outputStream = new FileOutputStream(dockerFile)) {
|
try (FileOutputStream outputStream = new FileOutputStream(dockerFile)) {
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int bytesRead;
|
int bytesRead;
|
||||||
@@ -53,9 +56,11 @@ public class JnaCallDllOrSo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.path = dockerFile.getAbsolutePath();
|
this.path = dockerFile.getAbsolutePath();
|
||||||
|
System.out.println("动态库路径: " + this.path);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("调用高级算法文件异常,异常信息如下:");
|
log.error("调用高级算法文件异常,异常信息如下:");
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage(), e);
|
||||||
|
throw new RuntimeException("加载动态库失败: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user