diff --git a/zstd/src/main/java/io/github/dfa1/zstd/NativeLibrary.java b/zstd/src/main/java/io/github/dfa1/zstd/NativeLibrary.java index 0923252..44372d8 100644 --- a/zstd/src/main/java/io/github/dfa1/zstd/NativeLibrary.java +++ b/zstd/src/main/java/io/github/dfa1/zstd/NativeLibrary.java @@ -41,9 +41,14 @@ static MethodHandle lookup(String name, FunctionDescriptor fd) { private static String extractBundledLib() { String classifier = classifier(); String ext = libExtension(classifier); - String resource = "/native/" + classifier + "/libzstd." + ext; + // Load through the class loader (no leading slash), not Class#getResourceAsStream: + // the library lives in a separate zstd-native- module, and a named + // module only finds resources in itself. The classifier directory name contains a + // dash, so it is not a valid package and the resource is not module-encapsulated — + // the class loader can read it across modules (and on the classpath alike). + String resource = "native/" + classifier + "/libzstd." + ext; - try (InputStream in = NativeLibrary.class.getResourceAsStream(resource)) { + try (InputStream in = NativeLibrary.class.getClassLoader().getResourceAsStream(resource)) { if (in == null) { throw new UnsatisfiedLinkError("No bundled zstd library found for platform " + classifier); } diff --git a/zstd/src/main/java/module-info.java b/zstd/src/main/java/module-info.java new file mode 100644 index 0000000..9ea4742 --- /dev/null +++ b/zstd/src/main/java/module-info.java @@ -0,0 +1,13 @@ +/// Java Foreign Function & Memory (FFM) bindings for Zstandard. +/// +/// Exports the single public API package; the native `libzstd` is loaded at +/// runtime from the platform `zstd-native-` artifact on the path. +/// Requires `--enable-native-access=io.github.dfa1.zstd` (or `ALL-UNNAMED` on +/// the classpath) since FFM downcalls are a restricted operation. +// The "dfa1" component ends in a digit, which the module-name lint flags as +// possibly version-like. It mirrors the Sonatype-verified io.github.dfa1 +// namespace and the package name, so suppress the advisory rather than diverge. +@SuppressWarnings("module") +module io.github.dfa1.zstd { + exports io.github.dfa1.zstd; +}