Packaging JNI Libraries


This question already has an answer here:


You can package the .dll into the .jar, but the physical .dll file must be unpackaged from there before it can be loaded because of how Windows handles .dlls. There's no way to load a .dll directly from inside the .jar.

This question seems to contain an appropriate implementation. Note, though, that it's somewhat error-prone: if the program hasn't write permissions to wherever it's going to extract the .dll,you're in a bizarre situation; you can't load the .dll because you don't have permissions to write it first.

A more robust solution is to use some kind of installer to install the whole application into a directory hierarchy such as

/whatEver/myApp/                 (The working directory of the app.)
/whatEver/myApp/myApp.jar        (The main app.)
/whatEver/myApp/lib/library.dll  (The JNI library.)

Then you can load the dll simply using a path relative to the working directory,


To be even more robust, you'll want to ensure that you're running a JVM with appropriate amount of bits before attempting to load the library. A little-advertised fact is that a 64-bit VM can't load 32-bit libraries, nor vice versa. See this question.

You might want to have a look at this: Since you did not provide any information about your build process, I can't help more.

Need Your Help

MS Access switching connection between test server and production SQL Server

sql-server ms-access azure azure-sql-database ms-access-2013

I'm developing a new MS Access 2013 desktop app with an Azure SQL Database backend. I plan to set up two backend servers, one for production, and one for testing.

R ggplot2 set color line by variable without grouping

r ggplot2

I'm trying to plot three different lines with ggplot2 that show the temporal series of three different variable (max, min and mean temperature). The problem comes when I want to set the color for e...