测试so动态库
This commit is contained in:
@@ -2,7 +2,6 @@ package com.njcn.advance.utils;
|
|||||||
|
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
import com.njcn.event.api.RmpEventDetailFeignClient;
|
|
||||||
import com.njcn.oss.utils.FileStorageUtil;
|
import com.njcn.oss.utils.FileStorageUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|||||||
@@ -22,35 +22,48 @@ 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
|
// windows操作系统为1 否则为0
|
||||||
int beginIndex = os != null && os.startsWith("Windows") ? 1 : 0;
|
int beginIndex = os != null && os.startsWith("Windows") ? 1 : 0;
|
||||||
if (beginIndex == 0) {
|
if (beginIndex == 0) {
|
||||||
//linux操作系统
|
//linux操作系统
|
||||||
this.nameDll = "lib" + name + "_dll.so";
|
this.nameDll = "lib" + name + "_dll";
|
||||||
|
suffix = ".so";
|
||||||
|
// this.path = "/usr/local/jarfiles/advanceboot/BOOT-INF/classes/";
|
||||||
|
|
||||||
this.path = "/usr/local/jarfiles/advanceboot/BOOT-INF/classes/";
|
|
||||||
//this.path = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8");
|
//this.path = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8");
|
||||||
} else {
|
} else {
|
||||||
this.nameDll = name + ".dll";
|
this.nameDll = name;
|
||||||
this.path = URLDecoder.decode(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().replaceFirst("/", ""), "UTF-8");
|
// 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());
|
log.error(e.getMessage());
|
||||||
}
|
}
|
||||||
/* if (JnaCallDllOrSo.jarPath.equals("")) {
|
|
||||||
JnaCallDllOrSo.jarPath = this.path.substring(0, this.path.lastIndexOf('/'));
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getStrpath() {
|
public String getStrpath() {
|
||||||
String aa = this.path + this.nameDll;
|
return this.path;
|
||||||
return aa.replace("/", File.separator);
|
// String aa = this.path + this.nameDll;
|
||||||
|
// return aa.replace("/", File.separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPath() {
|
public void setPath() {
|
||||||
|
|||||||
Reference in New Issue
Block a user