java程序打包后,调用第三方dll


//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());   
	}
	

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM