解决UnsatisfiedLinkError: Unable to load library:Native library not found in resource path

import java.io.UnsupportedEncodingException;

public class ClientDemo {
    public static String DLL_PATH;
    static {
        String path = (ClientDemo.class.getResource("/").getPath()).replaceAll("%20", " ").substring(1).replace("/",
                "\\");
        try {
            DLL_PATH = java.net.URLDecoder.decode(path, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}

调用:

    TscLibDll INSTANCE = (TscLibDll) Native.loadLibrary(ClientDemo.DLL_PATH + "TSCLIB.dll", TscLibDll.class);

其次亦可用:

    TscLibDll INSTANCE = (TscLibDll) Native
                .loadLibrary("E:\\zora_work\\zora\\zora\\WebRoot\\WEB-INF\\classes\\TSCLIB.dll", TscLibDll.class);

你可能感兴趣的:(java)