## February 13th, 2009

### JNI function names depend on the package name your Java code uses.

- You must do a System.loadLibrary( "mylib" ) [or System. load( "C:\\libs\\mylib.dll" ) for Windows] [or System.load( "lib/mylib.so" ) for Linux] before you can use any native methods of a class.

- All your DLLs and all the DLLs they indirectly invoke must live on the java.library.path. Only exception is System.load, which requires you to specify the full path to the .DLL.

- If you get the UnsatisfiedLinkError when you invoke a native method, check that the *.cpp method signatures exactly match those in the *.h file. You should see method names like this: Java_com_mindprod_mouse_Mouse_GetMousePosition that start with the word Java and contain the package, class and method name all strung together.

String libName = "MyNativeLib";String libNameOnPlatform = System.mapLibraryName(libName); // => "MyNativeLib.(dll|so)"// Search all the obvious places to try and find it.java.net.URL libUrl = ClassLoader.getSystemClassLoader().getResource(libNameOnPlatform); String libFullPath = libUrl.getPath(); // => "/c:\blah\blah.xxx"; note the leading "/" if(libFullPath.startsWith("/")) { libFullPath = libFullPath.substring(1); } if (! libFullPath.equals("")) { System.load(libFullPath);} else { throw new RuntimeException("Can't find native library - " + libNameOnPlatform);}