class HelloWorld {
public native void print(); //native method
static //static initializer code
{
try{
String path = System.getProperty("java.library.path");
System.out.println(path);
System.loadLibrary("CLibHelloWorld1");
//System.load("C:/TE_CDA_Project/Test/native/CLibHelloWorld1.dll");
//Runtime.getRuntime().load("C:/TE_CDA_Project/Test/native/CLibHelloWorld1.dll");
System.out.println("Loaded CallApi");
}catch(UnsatisfiedLinkError e){
e.printStackTrace();
}
}
public static void main(String[] args)
{
HelloWorld hw = new HelloWorld();
hw.print();
}
}
输出:
C:\TE_CDA_Project\Test\native
Loaded CallApi
Exception in thread "main" java.lang.UnsatisfiedLinkError: Graph.HelloWorld.print()V
at Graph.HelloWorld.print(Native Method)
at Graph.HelloWorld.main(HelloWorld.java:26)