Skip to content

Commit eb2a68f

Browse files
committed
1.26
1 parent 8ac5717 commit eb2a68f

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66

77
group 'dev.felnull'
88
archivesBaseName = "felnull-java-library"
9-
version '1.25'
9+
version '1.26'
1010

1111
repositories {
1212
mavenCentral()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dev.felnull.fnjl;
22

33
public class BuildIn {
4-
protected static final String VERSION = "1.25";
4+
protected static final String VERSION = "1.26";
55

66
protected static final int NATIVE_LIB_VERSION = 3;
77
}

src/main/java/dev/felnull/fnjl/jni/NativeLibraryManager.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)