Package org.zvec.binding
Class NativeLoader
java.lang.Object
org.zvec.binding.NativeLoader
Centralized, three-tier native library loader for the Zvec binding.
The binding depends on two native artifacts: the JavaCPP-generated JNI
glue (jnizvec) and the Zvec C-API shared library
(zvec_c_api). This loader resolves them with the following
precedence, mirroring the JavaCPP runtime model:
- Explicit path — when
-Dzvec.native.path=/dir(or theZVEC_NATIVE_PATHenvironment variable) is set, JavaCPP is steered to resolvezvec_c_apifrom that directory first (viapathsFirst+platform.preloadpath). Intended for local development and custom native builds. - Classpath / fat JAR — the default JavaCPP behavior extracts
the platform-specific libraries bundled under
<platform>/on the classpath (e.g. inside a self-contained fat JAR) to a cache directory and loads them. - System library path — if nothing is bundled, JavaCPP falls
back to the operating-system loader search path
(
java.library.path,LD_LIBRARY_PATH,PATH, ...).
Tier 1 configuration is applied as early as possible from the generated
ZvecNative's superclass initializer (presets.ZvecConfig), so it
takes effect regardless of which public entry point is touched first.
load() simply forces eager loading and converts low-level failures
into an actionable UnsatisfiedLinkError.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringEnvironment variable equivalent ofPATH_PROPERTY.static final StringSystem property naming an explicit directory that holds the native libraries. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidSteer JavaCPP toward the explicit native directory (tier 1) when one is configured.static StringResolve the configured explicit native directory, ornullwhen neither "zvec.native.path" nor "ZVEC_NATIVE_PATH" is set.static booleanisLoaded()Returnstrueonce the native libraries have been loaded.static voidload()Eagerly load the Zvec native libraries, applying the three-tier resolution described in the class documentation.
-
Field Details
-
PATH_PROPERTY
System property naming an explicit directory that holds the native libraries.- See Also:
-
PATH_ENV
Environment variable equivalent ofPATH_PROPERTY.- See Also:
-
-
Method Details
-
explicitPath
Resolve the configured explicit native directory, ornullwhen neither "zvec.native.path" nor "ZVEC_NATIVE_PATH" is set. The system property takes precedence over the environment variable. -
configure
public static void configure()Steer JavaCPP toward the explicit native directory (tier 1) when one is configured. Safe to call repeatedly and a no-op when no explicit path is set, so it may run during JavaCPP code generation without side effects.Must run before
ZvecNativetriggers its ownLoader.load(); this is guaranteed by invoking it from the generated class' superclass static initializer. -
load
public static void load()Eagerly load the Zvec native libraries, applying the three-tier resolution described in the class documentation. Idempotent.- Throws:
UnsatisfiedLinkError- if no native library can be resolved
-
isLoaded
public static boolean isLoaded()Returnstrueonce the native libraries have been loaded.
-