Skip to content

Commit 0d4e593

Browse files
committed
NativeUtils: added check of java.library.path presense
1 parent 053b91a commit 0d4e593

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/main/java/org/julia/jni/NativeUtils.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class NativeUtils {
4949
*/
5050
private static final int MIN_PREFIX_LENGTH = 3;
5151
public static final String NATIVE_FOLDER_PATH_PREFIX = "nativeutils";
52+
public static final String JAVA_LIBRARY_PATH = "java.library.path";
5253

5354
/**
5455
* Temporary directory which will contain the DLLs.
@@ -108,6 +109,7 @@ public static void loadLibraryFromJar(String path) throws IOException {
108109
throw new FileNotFoundException("File " + path + " was not found inside JAR.");
109110
}
110111

112+
checkJavaLibraryPath();
111113
try {
112114
System.load(temp.getAbsolutePath());
113115
} finally {
@@ -175,11 +177,23 @@ public static List<String> loadedLibraryNames() {
175177
final Field lib = ClassLoader.class.getDeclaredField("loadedLibraryNames");
176178
lib.setAccessible(true);
177179
Object list = lib.get(ClassLoader.getSystemClassLoader());
178-
if (list instanceof List)
180+
if (list instanceof List<?>)
179181
return (List<String>) list;
180182
} catch (IllegalAccessException | NoSuchFieldException e) {
181183
e.printStackTrace();
182184
}
183185
return Collections.emptyList();
184186
}
187+
188+
private static void checkJavaLibraryPath() {
189+
String javaLibraryPath = System.getProperty(JAVA_LIBRARY_PATH);
190+
String javaHome = System.getProperty("java.home");
191+
if (!javaLibraryPath.contains(javaHome)) {
192+
System.setProperty(JAVA_LIBRARY_PATH,
193+
javaLibraryPath + File.pathSeparator
194+
+ javaHome + File.separator + "lib"
195+
);
196+
}
197+
System.out.println(System.getProperty(JAVA_LIBRARY_PATH));
198+
}
185199
}

0 commit comments

Comments
 (0)