Reputation: 1845
I'm trying to import hdf.hdf5lib.H5 into my maven project in NetBeans. It has this as import line
import hdf.hdf5lib.H5;
as suggested here: https://support.hdfgroup.org/products/java/JNI3/jhi5/index.html
However, it throws this exception:
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - package hdf.hdf5lib does not exist
NetBeans already warned me about it by saying at the import line "packadge does not excist". So I let it "search dependencies at Maven repositories". It does find something and it adds this to my pom.xml:
<dependency>
<groupId>org.hdfgroup</groupId>
<artifactId>hdf-java</artifactId>
<version>2.6.1</version>
<type>jar</type>
</dependency>
Unfortunately it keeps the warning at the import line "packadge does not excist" and the error exception. It seems this addition to the pom.xml does nothing.
I am a beginner in all of this, so maybe the solution is obvious, but I cannot find it. These questions already date back to between 2012 and 2014, but didn't help me:
http://hdf-forum.184993.n3.nabble.com/maven-repository-for-java-release-td4026938.html
http://hdf-forum.184993.n3.nabble.com/HDF-Java-on-Maven-td4025772.html
add hdf5 libs (java & c++) to public maven repository?
How to use HDF5 in Windows Java project with NetBeans
Getting Started with hdf5 Java library
As suggested by ddarellis this might be a version problem. It seems there are two options.
I'll try both, but the suggestion from maven to use HDF Java 2.6.1 is wrong.
This post was helpfull for adding jarhdf5-3.3.2.jar to the dependencies.
https://forums.netbeans.org/post-62903.html#62903
Ok, so I installed HDF5 1.8.19 HDFView2.14 and added jarhdf5-3.3.2 to the dependencies. However I get this error when I try to run:
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at hdf.hdf5lib.H5.<clinit>(H5.java:230)
Upvotes: 8
Views: 3417
Reputation: 24443
The link you refer to contains out-of-date examples, you should use these examples instead.
As pointed by ddarellis, the correct package is:
ncsa.hdf.hdf5lib
Here is a working example of opening an HDF5 file:
import ncsa.hdf.hdf5lib.H5;
import ncsa.hdf.hdf5lib.HDF5Constants;
import ncsa.hdf.hdf5lib.exceptions.HDF5Exception;
public class Foo {
public void openHdf5File() {
int flags = HDF5Constants.H5P_DEFAULT;
int access = HDF5Constants.H5F_ACC_RDWR;
try {
int file_id = H5.H5Fopen("myFile.hdf", flags, access);
} catch (HDF5Exception ex) {
System.err.println("Failed to open HDF5 file");
}
}
}
The maven dependency you have is correct and is the latest available on maven central.
Upvotes: 6
Reputation: 3960
At the link you have posted you can see this at the top:
Very Important Change: Version 3.0 (and above) of the JHI5 packages all HDF library calls as "hdf.hd5flib", note that the "ncsa" has been removed. Source code which used earlier versions of the JHI5 should be changed to reflect this new implementation.
What this means is if you use lower library version from v3.0 which you are (v2.6.1) you have to include ncsa
.hdf.hdf5lib.H5 in-front of the package name.
You can find tutorials here.
Upvotes: 6