//getResourceAsStream以JAR中根路径为开始点
private synchronized static void loadLib(String libName) throws IOException {
String systemType = System.getProperty("os.name");
String libExtension = (systemType.toLowerCase().indexOf("win")!=-1) ? ".dll" : ".so";
String libFullName = libName + libExtension;
String nativeTempDir = System.getProperty("java.io.tmpdir");
InputStream in = null;
BufferedInputStream reader = null;
FileOutputStream writer = null;
File extractedLibFile = new File(nativeTempDir+File.separator+libFullName);
if(!extractedLibFile.exists()){
try {
in = ProgramMain.class.getClassLoader().getResourceAsStream("libs/"+libFullName);
if(in==null)
in = ProgramMain.class.getResourceAsStream(libFullName);
ProgramMain.class.getResource(libFullName);
reader = new BufferedInputStream(in);
writer = new FileOutputStream(extractedLibFile);
byte[] buffer = new byte[1024];
while (reader.read(buffer) > 0){
writer.write(buffer);
buffer = new byte[1024];
}
} catch (IOException e){
e.printStackTrace();
} finally {
if(in!=null)
in.close();
if(writer!=null)
writer.close();
}
}
System.load(extractedLibFile.toString());
}