My software build is _broken_ after upgrading to Gurobi 10.0.3 Maven package
OngoingDear all,
I am using the Gurobi optimizer as part of a Java application that I am developing. I am currently trying to move to the official Gurobi Maven 10.0.3 package. For this I have added the following to my `pom.xml`:
```xml
java.io.FileNotFoundException: Cannot load library libgurobi09.so.<!-- https://mvnrepository.com/artifact/com.gurobi/gurobi -->
<dependency>
<groupId>com.gurobi</groupId>
<artifactId>gurobi</artifactId>
<version>10.0.3</version>
</dependency>
```
I am now facing the following issue:
Everything works as before switching to the Gurobi Maven package, when running from _inside_ IntelliJ IDEA.
But it is not working anymore, when building the software with maven using this command:
```sh
mvn clean -Dmaven.test.skip=true -Denforcer.skip package
```
I get the following error, when I try to execute the software build like this:
```sh
$ java -Xmx8g -Djava.library.path=/opt/gurobi1003/linux64/lib -jar /home/micha/Documents/01_work/git/moma/target/MotherMachine-0.9.9.jar -tmax 10 -i /home/micha/Documents/01_work/15_moma_notes/02_moma_development/cleanup/20230929-clean-up-maven-pom-and-move-to-gurobi-maven-repo/20211026_VNG1040_AB6min_2h_1_MMStack_Pos7_GL12.tif
java.io.FileNotFoundException: Cannot load library libgurobi09.so.
------------------------------------------------------------------------
Make sure you either:
- define LD_LIBRARY_PATH (linux/macOS) or PATH (win) pointing to the gurobi library and JNI,
- download the full gurobi package (the core package does not include the libraries).
------------------------------------------------------------------------
at com.gurobi.gurobi.NativeUtils.copyLibToLocal(NativeUtils.java:52)
at com.gurobi.gurobi.NativeUtils.loadLibrariesFromJar(NativeUtils.java:30)
at com.gurobi.gurobi.GurobiJni.<clinit>(GurobiJni.java:326)
at com.gurobi.gurobi.GRBEnv.<init>(GRBEnv.java:68)
at com.gurobi.gurobi.GRBEnv.<init>(GRBEnv.java:44)
at com.jug.intialization.SetupValidator.checkGurobiInstallation(SetupValidator.java:13)
at com.jug.MoMA.main(MoMA.java:80)
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.gurobi.gurobi.GurobiJni.loadenv([JLjava/lang/String;IIII)I
at com.gurobi.gurobi.GurobiJni.loadenv(Native Method)
at com.gurobi.gurobi.GRBEnv.<init>(GRBEnv.java:68)
at com.gurobi.gurobi.GRBEnv.<init>(GRBEnv.java:44)
at com.jug.intialization.SetupValidator.checkGurobiInstallation(SetupValidator.java:13)
at com.jug.MoMA.main(MoMA.java:80)
```
For completeness' sake, these are my Gurobi environment variables, which are also used from inside IntelliJ IDEA (where they work):
```sh
export GRB_LICENSE_FILE="/home/micha/Documents/LicenseFiles/gurobi.lic"
export GUROBI_HOME="/opt/gurobi1003/linux64"
export PATH="${PATH}:${GUROBI_HOME}/bin"
export LD_LIBRARY_PATH="${GUROBI_HOME}/lib"
```
After a LOT of debugging and fiddling with the environment variables, I have now realized that the `<VERSION>` in `libgurobi<VERSION>.so` in the error message above, changes when I change the version string of _my_ software.
For example:
I get this output:
```sh
java.io.FileNotFoundException: Cannot load library libgurobi09.so.
```
with this setting in my `pom.xml`:
```
<properties>
</version.number>-->
<version.number>0.9.9</version.number>
...
</properties>
```
And I get this output:
```sh
java.io.FileNotFoundException: Cannot load library libgurobi100.so.
```
with this setting in my `pom.xml`:
```
<properties>
</version.number>-->
<version.number>10.0.0</version.number>
...
</properties>
```
(Note: The latter case also does not work, even though in this case the file name `libgurobi100.so` corresponds to the correct target-file (or so I assume): `/opt/gurobi1003/linux64/lib/libgurobi100.so`)
I suspect that this issue may have to do with the fact that I am building a FatJAR using the `maven-shade-plugin` in my `pom.xml` (I am happy to post more information on this, if needed - i.e. my full `pom.xml`).
I do not know how to fix this issue and it seems like it may be a bug in the Gurobi Maven package.
Any input on how to fix this would be greatly appreciated!
Best regards,
Michael
---
UPDATE:
The failing commands from above work without issues after switching back to the Git branch of the previous version (the one without the Gurobi Maven package). This (again) confirms that the settings of the Gurobi environment variables are not the problem.
-
Hi Michael,
This is a known issue with using the
maven-shade-plugin
. The reason is that for 10.0.3 we rely on information in the MANIFEST.MF, which is overridden when creating a fat jar.To fix this, you would need to put a ManifestResourceTransformer in your pom.xml and set:
Implementation-Title: com.gurobi:gurobi
Implementation-Version: 10.0.3I hope this is enough information to get you going! We aim to address this issue in future versions of the Java package so this will not be necessary anymore for fat jars.
0 -
Thank you for the quick reply. Could you provide me with a code-snippet of what the XML-fragment would look like for this transformer? I am not very familiar with this... Thanks.
---
UPDATE:
Is this correct (which I adapted from here)?
```xml
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Implementation-Title>com.gurobi:gurobi</Implementation-Title>
<Implementation-Version>10.0.3</Implementation-Version>
</manifestEntries>
</transformer>
```0
Please sign in to leave a comment.
Comments
2 comments