Java System.loadLibrary - Loading a Native DLL at Runtime

A Windows DLL (i.e. a Native Java Library, such as chilkat.dll) may be loaded at runtime by calling System.loadLibrary( dllFilename ), or System.load( dllFilePath ). For example:

    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
    }
	
    try {
        System.load("c:/temp/javaDeployTest/chilkat.dll");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
    }

With System.loadLibrary, you only specify the name of the DLL, such as "chilkat". The JVM (java runtime) will search for the DLL in the directories listed in java.library.path system property. This property may be set on the command line with the -D option:

java -Djava.library.path=c:\temp\myNativeDlls myTestApp
	
<strong>NOTE:</strong> There should be no SPACE character between the "-D" and the "java.library.path".
The lack of a SPACE character is correct.

The System.load method is more straightforward and allows you to specify the filepath of the native library directly.

 

 

Link: http://www.chilkatsoft.com/p/p_499.asp 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值