@@ -21,6 +21,7 @@ public class NativeLibraryManager {
2121 private static boolean inited ;
2222 private static boolean load ;
2323 private static Path libraryFolder ;
24+ private static String relocatePath ;
2425
2526 /**
2627 * JNIライブラリを読み込む
@@ -39,6 +40,15 @@ public static void loadLibrary() {
3940 }
4041 }
4142
43+ /**
44+ * ShadowJarなどでNativeライブラリの場所を変更してる場合に指定
45+ *
46+ * @param relocatePath 移動パス
47+ */
48+ public static void setRelocatePath (String relocatePath ) {
49+ NativeLibraryManager .relocatePath = relocatePath ;
50+ }
51+
4252 /**
4353 * 読み込みに失敗したかどうか
4454 *
@@ -93,10 +103,10 @@ private static void extractLibrary(OSs.Type os, String aarch) throws IOException
93103 String libname = "FNJL" + aarch + "." + os .getLibName ();
94104 String pp = FelNullJavaLibrary .class .getPackage ().getName ().replace ("." , "/" ) + "/natives/" + libname ;
95105
96- InputStream stream = NativeLibraryManager . class . getResourceAsStream ( "/" + pp );
106+ InputStream stream = loadResource ( pp );
97107
98- if (stream == null )
99- stream = ClassLoader . getSystemResourceAsStream ( pp );
108+ if (stream == null && relocatePath != null )
109+ stream = loadResource ( relocatePath + "/" + libname );
100110
101111 if (stream == null )
102112 throw new IOException ("Library does not exist" );
@@ -106,4 +116,12 @@ private static void extractLibrary(OSs.Type os, String aarch) throws IOException
106116
107117 Files .write (path , FNDataUtil .streamToByteArray (stream ));
108118 }
119+
120+ private static InputStream loadResource (String path ) {
121+ InputStream stream = NativeLibraryManager .class .getResourceAsStream ("/" + path );
122+ if (stream == null )
123+ stream = ClassLoader .getSystemResourceAsStream (path );
124+ return stream ;
125+ }
126+
109127}
0 commit comments