cmake(java): allow to not load highs or scip dll.

should fix #4600
This commit is contained in:
Mizux Seiha
2025-03-28 16:25:18 +01:00
committed by Corentin Le Molgat
parent d7077ba43b
commit 61091ff4af

View File

@@ -29,6 +29,8 @@ import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.AbstractMap;
import java.util.Objects;
/** Load native libraries needed for using ortools-java. */
@@ -141,19 +143,30 @@ public class Loader {
try {
URI resourceURI = getNativeResourceURI();
Path tempPath = unpackNativeResources(resourceURI);
// libraries order does matter !
List<String> dlls = Arrays.asList("zlib1", "abseil_dll", "re2", "utf8_validity",
"libprotobuf", "highs", "libscip", "ortools", "jniortools");
for (String dll : dlls) {
// libraries order does matter <LibraryName, isMandatory> !
List<Map.Entry<String,Boolean>> dlls = Arrays.asList(
(new AbstractMap.SimpleEntry("zlib1", true)),
(new AbstractMap.SimpleEntry("abseil_dll", true)),
(new AbstractMap.SimpleEntry("re2", true)),
(new AbstractMap.SimpleEntry("libutf8_validity", true)),
(new AbstractMap.SimpleEntry("libprotobuf", true)),
(new AbstractMap.SimpleEntry("highs", false)),
(new AbstractMap.SimpleEntry("libscip", false)),
(new AbstractMap.SimpleEntry("ortools", true)),
(new AbstractMap.SimpleEntry("jniortools", true)));
for (Map.Entry<String,Boolean> dll : dlls) {
try {
// System.out.println("System.load(" + dll + ")");
//System.out.println("System.load(" + dll.getKey() + ")");
System.load(tempPath.resolve(RESOURCE_PATH)
.resolve(System.mapLibraryName(dll))
.resolve(System.mapLibraryName(dll.getKey()))
.toAbsolutePath()
.toString());
} catch (UnsatisfiedLinkError e) {
System.out.println("System.load(" + dll + ") failed!");
throw new RuntimeException(e);
System.out.println("System.load(" + dll.getKey() + ") failed!");
if(dll.getValue()) {
throw new RuntimeException(e);
}
}
}
loaded = true;