Add hdf5-native Maven JARs and SciJava native-lib-loader integration#6356
Add hdf5-native Maven JARs and SciJava native-lib-loader integration#6356matteodg wants to merge 7 commits into
Conversation
|
Must Fix: The FFM [H5.java:314] calls Hdf5NativeLoader.loadBundledNativesIfPresent(false) with no try-catch in the static block. If native-lib-loader-2.5.0.jar is missing from the classpath, loading Hdf5NativeLoader will throw NoClassDefFoundError (because it imports org.scijava.nativelib.NativeLoader), which will cause an ExceptionInInitializerError that permanently prevents H5 from being used in that JVM. The JNI [H5.java:366-374] correctly wraps the call in catch (Throwable err), which handles this. The FFM version does not. The FFM path should have the same protection. Nice to have:
Moderate:
Low Severity
Consider using a simpler pattern like hdf5-(java|native|jni-native) or an array-based check.
Verify:
|
brtnfld
left a comment
There was a problem hiding this comment.
"Must Fix" needs to be addressed.
4779e1e to
f7e31e1
Compare
2a04368 to
cbf65fa
Compare
In both java/hdf/hdf5lib/H5.java (FFM) and java/src-jni/hdf/hdf5lib/H5.java (JNI), replace: with:
In java/cmake/HDF5JavaNativeBundles.cmake: Nice to have:
java/cmake/pom-native.xml.in and java/cmake/pom-jni-native.xml.in both end without a newline (\ No newline at end of file). Add a newline at the end of each.
The problem: isHdf5LibraryLoaded is set in two unrelated places with different meanings: In the bundled loader block — means "bundled hdf5 loaded" — split the flag's responsibilities): Replace the two flags with three, each with a single clear meaning: Change the early-exit guard from: to: Change the H5.H5dont_atexit() block from: to: This way isHdf5LibraryLoaded tracks only the bundled load result, isHdf5JavaLibraryLoaded tracks only the JNI bridge load result, and isInitialized guards against redundant re-entry. |
Introduce java/lib/vendored-jars.sha256 and a CI workflow that runs sha256sum -c against it (no network). Document SLF4J in java/lib/NOTICES.txt.
Add org.scijava:native-lib-loader 2.5.0 under java/lib for consistent classpath use (examples cache includes the JAR alongside SLF4J). Define HDF5_JAVA_NATIVE_LIB_LOADER_JAR for downstream CMake consumers. Add offline SHA-256 verification for java/lib JAR too.
cbf65fa to
02937dc
Compare
…a native-lib-loader Introduce HDF5JavaNativeBundles.cmake to stage shared libraries under natives/<platform>/ (SciJava native-lib-loader layout), emit manifests with Implementation-Version, and add pom-native / pom-jni-native templates. Wire FFM and JNI hdf.hdf5lib builds and install the native-lib-loader JAR with other Java dependencies. Register add_subdirectory(java) before printing Maven deploy status so Java targets and globals exist before the examples subdirectory pulls in HDF5ExampleCache.cmake. Add Hdf5NativeLoader (thin wrapper over NativeLoader) and call it from H5 for FFM and JNI before loading JNI. Declare org.scijava:native-lib-loader in generated POMs. Preserves skip/override properties documented in INSTALL.
Include HDF5_JAVA_NATIVE_LIB_LOADER_JAR alongside logging JARs so unit tests compile and run the same classpath layout as production JARs.
Extend artifact validation for native classifier JARs and adjust workflows (ctest, maven-staging, maven-deploy) for the new native bundle layout and dependencies. Copy POMs from FFM vs JNI CMake output paths instead of matching any pom.xml under the build tree. ctest uses ACTIVE_PRESET *Maven-FFM* and fails if both trees contain pom.xml. maven-staging branches on matrix.implementation and validates exactly one pom.xml in artifacts.
Describe hdf5-native / classpath layout, SciJava loader usage, Hdf5NativeLoader, and release notes touch-up for published artifacts. Document that bundled native loading may partially succeed (libhdf5 loaded even if JNI bridge load fails) and clarify that transitive native dependencies like zlib/szip/plugins are not bundled in the Maven native JARs.
0eb14bb to
736bd89
Compare
736bd89 to
0bcd2dc
Compare
Fixes #6355
I created this with Cursor, as my knowledge of CMake is basically zero: I tried to do it myself, but I was not able. I tested this in Linux x86_64 and Windows x86_64 and it is creating the proper jar and pom.xml file, that I can install in my local Maven repository and depend on them from an example application. This was there is not need of installing HDF5 library or setting up
LD_LIBRARY_PATHanymore.This will be useful for the future of HDFView as well.