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 

你可能感兴趣的:(Runtime)