Sotirios-Efstathios Maneas

About Sotirios-Efstathios Maneas

Sotirios-Efstathios (Stathis) Maneas is a postgraduate student at the Department of Informatics and Telecommunications of The National and Kapodistrian University of Athens. His main interests include distributed systems, web crawling, model checking, operating systems, programming languages and web applications.

java.library.path – What is it and how to use

In this tutorial we will discuss about java.library.path, its definition and how can be used by Java applications. The Java Virtual Machine (JVM) uses the java.library.path property in order to locate native libraries. This property is part of the system environment used by Java, in order to locate and load native libraries used by an application.

When a Java application loads a native library using the System.loadLibrary() method, the java.library.path is scanned for the specified library. If the JVM is not able to detect the requested library, it throws an UnsatisfiedLinkError. Finally, the usage of native libraries makes a Java program more platform dependent, as it requires the existence of specific native libraries.

How to set the java.library.path property

There are several ways to set the java.library.path property:

  • Through the command line or terminal: Using the terminal (Linux or Mac) or the command prompt (Windows), we can execute the following command, in order to execute our Java application:
    	java -Djava.library.path=<path_to_dll> <main_class>
    	

    where the path_to_dll argument must be replaced with the path of the required library.

  • Through Java source code: Inside an application’s code we can set the java.library.path using the following code snippet:
    	System.setProperty(“java.library.path”, “/path/to/library”);
    	
  • Through an IDE: The java.library.path can be configured using an IDE, such as Eclipse or Netbeans.
  • Setting the java.library path. using Eclipse

    In order to define the java.library.path property in Eclipse, the following steps must be completed:

    1. Select your project in the Package Explorer area and press a right click on it.
    2. Select Build PathConfigure Build Path... option.
    3. In the appearing window, select the Libraries tab.
    4. Then, expand the JRE System library option and select the Native library location.
    5. Click on the Edit... button at the right panel.
    6. Locate the required library and then click OK.
    7. Close the window.

    If the aforementioned steps have been successfully completed, then the selected project will be executed using the required native library.

    Setting the java.library path. using Netbeans

    In order to define the java.library.path property in Netbeans, the following steps must be completed:

    1. Select your project in the Projects area and press a right click on it.
    2. Select Properties and then, move to the Run tab.
    3. In the VM Options field, add the following option, based on your library’s path:
      java -Djava.library.path=<path_to_dll>

    4. Click on OK in order for the window to close.

    If the aforementioned steps have been successfully completed, then the selected project will be executed using the required native library.

     
    This was a tutorial about the java.library.path property in Java.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.
Examples Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Examples Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Examples Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close