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.