1

I am trying to use Gurobi 8.1 in a Java project. I have set the following environment variables at my .zshrc:

export GUROBI_HOME="/home/user/tool/gurobi811/linux64"
export PATH="${PATH}:${GUROBI_HOME}/bin"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib"
export GRB_LICENSE_FILE="/home/user/tool/gurobi811/gurobi.lic"

This was done according to these links: Software Installation Guide and Setting environment variables. This allows me to successfully run the interactive shell of the optimizer.

However, I get the following error when trying to use the optimizer in a Netbeans project:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no GurobiJni81 in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2660)
    at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:829)
    at java.base/java.lang.System.loadLibrary(System.java:1867)
    at gurobi.GurobiJni.<clinit>(GurobiJni.java:261)
    at gurobi.GRBEnv.<init>(GRBEnv.java:56)
    at br.gurobi.test.main.Main.main(Main.java:31)
/home/user/project/nbproject/build-impl.xml:1328: The following error occurred while executing this line:
/home/user/project/nbproject/build-impl.xml:948: Java returned: 1
BUILD FAILED (total time: 0 seconds)

If I use the -Djava.library.path=/path/to/lib option (as used here), I get another error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/user/tool/gurobi811/linux64/lib/libGurobiJni81.so: libgurobi81.so: cannot open shared object file: No such file or directory
    at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
    at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2430)
    at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2487)
    at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2684)
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2649)
    at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:829)
    at java.base/java.lang.System.loadLibrary(System.java:1867)
    at gurobi.GurobiJni.<clinit>(GurobiJni.java:261)
    at gurobi.GRBEnv.<init>(GRBEnv.java:56)
    at br.gurobi.test.main.Main.main(Main.java:31)
/home/user/project/nbproject/build-impl.xml:1328: The following error occurred while executing this line:
/home/user/project/nbproject/build-impl.xml:948: Java returned: 1
BUILD FAILED (total time: 0 seconds)

I have added both gurobi.jar and gurobi-javadoc.jar to my project compile-time libraries. I did not find a place in Apache Netbeans 11 to define the environment variables.

alexandredias3d
  • 361
  • 3
  • 17
  • 1
    It looks like [someone else also had your problem with NetBeans 8.2/Gurobi 8.1](https://groups.google.com/forum/#!msg/gurobi/x5wLf2kGfBc/hJr78-4d28UJ), though no solution was offered. – skomisa May 14 '19 at 00:13

3 Answers3

1

I never found a "nice" way of setting environment variables on the project/target level with newer Netbeans versions. A hack that works though is adding the LD_LIBRARY_PATH setting globally to netbeans, i.e., edit <your netbeans install directory>/etc/netbeans.conf to include the line

export LD_LIBRARY_PATH=<absolute path to the gurobi lib dir>

One could set such environment variables globally on the OS level, too, but that's even more ugly.

A presumably better solution would be a custom Ant script within the Netbeans project that sets the appropriate enviroment variables, but since the hack above is good enough for my purpose, I never pursued that any further.

Robert
  • 575
  • 3
  • 12
0

I could manage to run the optimizer by executing Netbeans from the terminal (where all my user variables were already set).

Still, I will wait for an answer that shows how to set environment variables directly on Netbeans.

alexandredias3d
  • 361
  • 3
  • 17
0

I've got the same problem with IntelliJ and here it is my solution: simply run your IDE from the terminal and try running your program. As far as I noticed, the global environment variables defined in .zshrc (.bashrc file in my case since i'm using Ubuntu) will be loaded and the program will work!

Davide
  • 1
  • 1