Loading a native library in Java on Windows

I’ve been struggling a bit with Java on Windows when I have needed to load a native library required by the application I’m currently working on (believe it or not a Java desktop application. Yes they still exist! 🙂 There are several options:

  • Load from an explicitly specified absolute path using the System.load call.
  • Make sure the DLL is in one of the paths listed in “java.library.path”

Handy tip: if running IntelliJ grab the code from and use it for a new Scratch file. It’s an easy way to get the value for your java.library.path.

  • Modify the Windows system PATH environment variable to include the folder where the DLL is stored.
  • Passing the “java.library.path” on the command line to the java runtime by using the -D option.

The best resource I found that helped me a lot was this page from Chilkat Software (and where the 4 items above were directly cribbed from! Thank you!).

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: