Skip to content

Commit d5ef07a

Browse files
committed
Update NativeLibraryLoader
1. Remove LWJGL dependencies. 2. Add class 'NativeLibraryLoaderConfig'. 3. Update class 'NativeLibraryLoader'.
1 parent 5de7499 commit d5ef07a

4 files changed

Lines changed: 43 additions & 30 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This project requires Java 26 and preview features enabled.
1010

1111
Before calling any method you need to load the native library. For Windows and Linux you can call ```Jolt.loadNativeLibrary()```. Additionally you need to initialize jolt with a call to ```Jolt.init()``` (do not forget to call ```Jolt.shutdown``` when jolt is no longer needed).
1212

13-
My implementation of a native library loader makes use of some [LWJGL](https://www.lwjgl.org/) configurations. To set the extract directory of the native library, change ```Configuration.SHARED_LIBRARY_EXTRACT_PATH```.
13+
To set the extract directory of the native library, change ```NativeLibraryLoaderConfig.SHARED_LIBRARY_EXTRACT_PATH```.
1414

1515
Due to the introduction of [restricted methods](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/doc-files/RestrictedMethods.html), it is recommended (and in later versions required) to run the application with the VM argument ```--enable-native-access=ALL-UNNAMED```.
1616

pom.xml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,7 @@
7979
<lwjgl.windows.natives>natives-windows</lwjgl.windows.natives>
8080
<lwjgl.linux.natives>natives-linux</lwjgl.linux.natives>
8181
</properties>
82-
<dependencyManagement>
83-
<dependencies>
84-
<dependency>
85-
<groupId>org.lwjgl</groupId>
86-
<artifactId>lwjgl-bom</artifactId>
87-
<version>${lwjgl.version}</version>
88-
<scope>import</scope>
89-
<type>pom</type>
90-
</dependency>
91-
</dependencies>
92-
</dependencyManagement>
9382
<dependencies>
94-
<dependency>
95-
<groupId>org.lwjgl</groupId>
96-
<artifactId>lwjgl</artifactId>
97-
</dependency>
98-
<dependency>
99-
<groupId>org.lwjgl</groupId>
100-
<artifactId>lwjgl</artifactId>
101-
<classifier>${lwjgl.windows.natives}</classifier>
102-
</dependency>
103-
<dependency>
104-
<groupId>org.lwjgl</groupId>
105-
<artifactId>lwjgl</artifactId>
106-
<classifier>${lwjgl.linux.natives}</classifier>
107-
</dependency>
10883
<dependency>
10984
<groupId>com.github.spotbugs</groupId>
11085
<artifactId>spotbugs-annotations</artifactId>

src/main/java/volucris/bindings/core/NativeLibraryLoader.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import java.nio.file.StandardCopyOption;
1010
import java.util.ArrayList;
1111

12-
import org.lwjgl.system.Configuration;
13-
1412
public final class NativeLibraryLoader {
1513

1614
private static final String OS = System.getProperty("os.name").toLowerCase();
@@ -30,11 +28,11 @@ public final class NativeLibraryLoader {
3028
static {
3129
EXTRACT_PATHS = new ArrayList<String>();
3230

33-
String extractPath = Configuration.SHARED_LIBRARY_EXTRACT_PATH.get();
31+
String extractPath = NativeLibraryLoaderConfig.SHARED_LIBRARY_EXTRACT_PATH.getValue();
3432
if (extractPath != null)
3533
EXTRACT_PATHS.add(extractPath + File.separator);
3634

37-
String extractDirectory = Configuration.SHARED_LIBRARY_EXTRACT_DIRECTORY.get();
35+
String extractDirectory = NativeLibraryLoaderConfig.SHARED_LIBRARY_EXTRACT_DIRECTORY.getValue();
3836
if (extractDirectory == null) {
3937
extractDirectory = "volucris_bindings";
4038
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package volucris.bindings.core;
2+
3+
import edu.umd.cs.findbugs.annotations.Nullable;
4+
5+
public final class NativeLibraryLoaderConfig {
6+
7+
public static final NativeLibraryLoaderConfig SHARED_LIBRARY_EXTRACT_PATH = new NativeLibraryLoaderConfig(
8+
"volucris.bindings.sharedLibraryExtractPath");
9+
public static final NativeLibraryLoaderConfig SHARED_LIBRARY_EXTRACT_DIRECTORY = new NativeLibraryLoaderConfig(
10+
"volucris.bindings.sharedLibraryExtractDirectory");
11+
12+
private final String propertyName;
13+
14+
private @Nullable String value;
15+
16+
public NativeLibraryLoaderConfig(String propertyName) {
17+
this.propertyName = propertyName;
18+
this.value = System.getProperty(propertyName);
19+
}
20+
21+
public final String getPropertyName() {
22+
return propertyName;
23+
}
24+
25+
public final void setValue(@Nullable String value) {
26+
this.value = value;
27+
}
28+
29+
public @Nullable String getValue() {
30+
return value;
31+
}
32+
33+
public String getValueOrDefault(String defaultValue) {
34+
if (value == null)
35+
return defaultValue;
36+
37+
return value;
38+
}
39+
40+
}

0 commit comments

Comments
 (0)