問題: 如何建立包含您的程式碼的單一JAR 檔案(第三方JAR) ,及其附帶的DLL檔?
答案:要將DLL 檔案打包到JAR 中,請依照下列步驟操作:
範例程式碼:
提供的Java程式碼示範了一種將 DLL 從 JAR載入的方法記憶體:
public class Foo { static { System.loadLibrary(ACWRAPPER); } private static void loadFromJar() { // Extract DLLs to a temporary location String path = "AC_" + new Date().getTime(); loadLib(path, ACWRAPPER); loadLib(path, AAMAPI); loadLib(path, LIBEAU); } private static void loadLib(String path, String name) { name = name + ".dll"; try { InputStream in = ACWrapper.class.getResourceAsStream(LIB_BIN + name); File fileOut = new File(System.getProperty("java.io.tmpdir") + "/" + path + LIB_BIN + name); OutputStream out = FileUtils.openOutputStream(fileOut); IOUtils.copy(in, out); System.load(fileOut.toString()); } catch (Exception e) { throw new ACCoreException("Failed to load required DLL", e); } } }
註解:
以上是如何將 DLL 與 Java 程式碼打包到單一 JAR 檔案中?的詳細內容。更多資訊請關注PHP中文網其他相關文章!