欣影管理平台装置通道表修改

jni
liuguijing 2 years ago
parent b0d47bb571
commit 185488d9da

@ -3,8 +3,10 @@ package com.shxy.xymanager_service.interaction;
public class Cma { public class Cma {
static { static {
System.setProperty("java.library.path", "./libs"); // System.setProperty("java.library.path", "./libs");
System.loadLibrary("xympj"); // System.loadLibrary("xympj");
// LibLoader.loadLib("xympj.dll");
System.load("D:\\Project\\JAVAProject\\XyManagerBackend\\libs\\xympj.dll");
initCmaEnv(); initCmaEnv();
} }
@ -23,7 +25,7 @@ public class Cma {
} }
} }
private static native boolean initCmaEnv(); public static native boolean initCmaEnv();
public native long initCma(String server, int port); public native long initCma(String server, int port);
public native void releaseCma(long cma); public native void releaseCma(long cma);

@ -0,0 +1,8 @@
package com.shxy.xymanager_service.interaction;
import com.sun.jna.Library;
import com.sun.jna.Native;
public class CmaDLL implements Library {
CmaDLL INSTANCE = (CmaDLL) Native.loadLibrary("xympj.dll",CmaDLL.class);
}

@ -0,0 +1,29 @@
package com.shxy.xymanager_service.interaction;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.InputStream;
public class LibLoader {
public static void loadLib(String libName) {
String resourcePath = "/" + libName;
String folderName = System.getProperty("java.io.tmpdir") + "/lib/";
File folder = new File(folderName);
folder.mkdirs();
File libFile = new File(folder, libName);
if (libFile.exists()) {
System.load(libFile.getAbsolutePath());
} else {
try {
InputStream in = LibLoader.class.getResourceAsStream(resourcePath);
FileUtils.copyInputStreamToFile(in, libFile);
in.close();
System.load(libFile.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Failed to load required lib", e);
}
}
}
}
Loading…
Cancel
Save