测试so动态库

This commit is contained in:
2023-08-18 16:13:38 +08:00
parent 3ede2a285a
commit a235d143c0
2 changed files with 26 additions and 14 deletions

View File

@@ -2,7 +2,6 @@ package com.njcn.advance.utils;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.CharsetUtil;
import com.njcn.event.api.RmpEventDetailFeignClient;
import com.njcn.oss.utils.FileStorageUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

View File

@@ -22,35 +22,48 @@ public class JnaCallDllOrSo {
public JnaCallDllOrSo(String name) {
super();
String suffix = ".dll";
try {
String os = System.getProperty("os.name");
// windows操作系统为1 否则为0
int beginIndex = os != null && os.startsWith("Windows") ? 1 : 0;
if (beginIndex == 0) {
//linux操作系统
this.nameDll = "lib" + name + "_dll.so";
this.path = "/usr/local/jarfiles/advanceboot/BOOT-INF/classes/";
this.nameDll = "lib" + name + "_dll";
suffix = ".so";
// this.path = "/usr/local/jarfiles/advanceboot/BOOT-INF/classes/";
//this.path = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8");
} else {
this.nameDll = name + ".dll";
this.path = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().replaceFirst("/", ""), "UTF-8");
this.nameDll = name;
// this.path = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().replaceFirst("/", ""), "UTF-8");
}
} catch (UnsupportedEncodingException e) {
File tempFile;
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(this.nameDll.concat(suffix))) {
tempFile = File.createTempFile(this.nameDll, suffix);
try (FileOutputStream outputStream = new FileOutputStream(tempFile)) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
}
}
this.path = tempFile.getAbsolutePath();
System.out.println(1);
System.out.println(1);
} catch (Exception e) {
log.error(e.getMessage());
}
/* if (JnaCallDllOrSo.jarPath.equals("")) {
JnaCallDllOrSo.jarPath = this.path.substring(0, this.path.lastIndexOf('/'));
}*/
}
public String getStrpath() {
String aa = this.path + this.nameDll;
return aa.replace("/", File.separator);
return this.path;
// String aa = this.path + this.nameDll;
// return aa.replace("/", File.separator);
}
public void setPath() {