Skip to content

Commit a7bb08c

Browse files
authored
Update README.md: replaced the examples with updateable examples
1 parent ac841ca commit a7bb08c

File tree

1 file changed

+4
-50
lines changed

1 file changed

+4
-50
lines changed

README.md

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -75,61 +75,15 @@ dependencyResolutionManagement {
7575
```
7676
### Library Implementation:
7777
1) The most straightforward way:
78-
```java
79-
final LibraryInfo info = new LibraryInfo(new DirectoryPath("lib/independent"), "basename", DirectoryPath.USER_DIR);
80-
// or
81-
// final LibraryInfo info = new LibraryInfo(DirectoryPath.CLASS_PATH,
82-
// new DirectoryPath("lib/independent"), "basename", DirectoryPath.USER_DIR);
83-
final NativeBinaryLoader loader = new NativeBinaryLoader(info);
84-
final NativeDynamicLibrary[] libraries = new NativeDynamicLibrary[] {
85-
new NativeDynamicLibrary("lib/linux/x86-64", PlatformPredicate.LINUX_X86_64),
86-
new NativeDynamicLibrary("lib/macos/arm-64", PlatformPredicate.MACOS_ARM_64),
87-
new NativeDynamicLibrary("lib/macos/x86-64", PlatformPredicate.MACOS_X86_64),
88-
new NativeDynamicLibrary("lib/win/x86-64", PlatformPredicate.WIN_X86_64)
89-
...
90-
};
91-
loader.registerNativeLibraries(libraries).initPlatformLibrary();
92-
loader.setLoggingEnabled(true);
93-
loader.setRetryWithCleanExtraction(true);
94-
try {
95-
loader.loadLibrary(LoadingCriterion.INCREMENTAL_LOADING);
96-
} catch (IOException e) {
97-
Logger.getLogger(NativeBinaryLoader.class.getName()
98-
.log(Level.SEVERE, "Native loader has failed!", e);
99-
}
100-
```
78+
https://github.com/Electrostat-Lab/jSnapLoader/blob/ac841ca914c1aba82c3bea0dfb3176a094712c7e/snaploader-examples/src/main/java/electrostatic4j/snaploader/examples/TestCrossPlatformClassPathLoading.java#L44-L72
79+
10180
- This way utilizes the classpath on the stock Jar archive to locate, extract and load the native binaries.
10281
- It first defines a library info object with a pointer to the classpath (aka. wrapped null string path), and a default path that will be
10382
used in case the platform path for the selected platform predicate is not assigned, then a `basename` for the library to be operated, and finally the current working directory as an extraction path.
10483

10584
2) A Superior control:
106-
```java
107-
import java.nio.file.Path;
108-
import java.nio.file.Paths;
109-
...
110-
// compatible with Java 8, Since 1.7
111-
final Path compression = Paths.get(PropertiesProvider.USER_DIR.getSystemProperty(), "libs", "electrostatic4j.jar");
112-
// create extraction path directory if not exists
113-
final Path extractionPath = Files.createDirectories(Paths.get(PropertiesProvider.USER_DIR.getSystemProperty(), "libs", "natives"));
114-
final LibraryInfo info = new LibraryInfo(new DirectoryPath(compression.toString()), new DirectoryPath("lib/independent"), "electrostatic4j", new DirectoryPath(extractionPath.toString()));
115-
final NativeBinaryLoader loader = new NativeBinaryLoader(info);
116-
final NativeDynamicLibrary[] libraries = new NativeDynamicLibrary[] {
117-
new NativeDynamicLibrary("lib/linux/x86-64", PlatformPredicate.LINUX_X86_64),
118-
new NativeDynamicLibrary("lib/macos/arm-64", PlatformPredicate.MACOS_ARM_64),
119-
new NativeDynamicLibrary("lib/macos/x86-64", PlatformPredicate.MACOS_X86_64),
120-
new NativeDynamicLibrary("lib/win/x86-64", PlatformPredicate.WIN_X86_64)
121-
...
122-
};
123-
loader.registerNativeLibraries(libraries).initPlatformLibrary();
124-
loader.setLoggingEnabled(true);
125-
loader.setRetryWithCleanExtraction(true);
126-
try {
127-
loader.loadLibrary(LoadingCriterion.INCREMENTAL_LOADING);
128-
} catch (IOException e) {
129-
Logger.getLogger(NativeBinaryLoader.class.getName()
130-
.log(Level.SEVERE, "Native loader has failed!", e);
131-
}
132-
```
85+
https://github.com/Electrostat-Lab/jSnapLoader/blob/ac841ca914c1aba82c3bea0dfb3176a094712c7e/snaploader-examples/src/main/java/electrostatic4j/snaploader/examples/TestBasicFeatures2.java#L48-L82
86+
13387
- This way utilizes the `java.nio.file.Paths` and `java.nio.file.Path` APIs to build platform-independent directory paths, and it's deemed the most superior way, especially for vague systems; thus it's considered the most robust way, and the best cross-platform strategy; because it depends on the Java implementation for this specific runtime.
13488

13589
3) Full control (external Jar localizing, platform predicates, and platform-independent extraction paths):

0 commit comments

Comments
 (0)