Skip to content
Advertisement

UnsatisfiedLinkError on System.loadLibrary() after adding the directory to java.library.path

I would like to load the local library /opt/gurobi902/linux64/lib/libGurobiJni90.so within my Java IntelliJ Maven project on Ubuntu 19.10.

My first attempt was adding the environment variable LD_LIBRARY_PATH like this: export LD_LIBRARY_PATH="/opt/gurobi902/linux64/lib" (I know I have completly overwritten it instead of appending to it, because it was not set at all previously.)

I thought it worked, because when I run the terminal command java -XshowSettings:propertiesjava -XshowSettings:properties it returns this (among other things):

java.library.path = /opt/gurobi902/linux64/lib
        /usr/java/packages/lib
        /usr/lib/x86_64-linux-gnu/jni
        /lib/x86_64-linux-gnu
        /usr/lib/x86_64-linux-gnu
        /usr/lib/jni
        /lib
        /usr/lib

BUT when I want to load the library in my project with System.loadLibrary("GurobiJni90") I receive this exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no GurobiJni90 in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]

As you can see, the directory I’ve added previously is not listed in java.library.path of the exception statement.

Btw. this is my pom.xml entry for the library:

<dependency>
    <groupId>com.gurobi</groupId>
    <artifactId>gurobi</artifactId>
    <version>9.0.2</version>
    <scope>system</scope>
    <systemPath>/opt/gurobi902/linux64/lib/gurobi.jar</systemPath>
</dependency>

Advertisement

Answer

The issue is fixed now!

It seems like my linux distribution (Ubuntu 19.10) doesn’t allow applications to read the .bashrc file where the environment variables are set. This explains why java.library.path hold different contents when accessed from the terminal or my own IntelliJ project.

The Gurobi Installation Guide mentions this issue (but I thought I wasn’t affected):

In some Linux distributions, applications launched from the Linux desktop won’t read .bashrc (or .cshrc). You may need to set the Gurobi environment variables in .bash_profile or .profile instead. Unfortunately, the details of where to set these variables vary widely among different Linux distributions. We suggest that you consult the documentation for your distribution if you run into trouble.

I’ve added the environment variables manually to my project in IntelliJ via the menu [Run] > [Edit Configurations] > [Environment variables] since I need them only in this project. Works for me!

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement