Reading an HDF5 file in Java

I'm trying to open/read an existing HDF5 file using the Java library. I
have the "jhdf.dll" and "jhdf5.dll" files on the system path. The code I
have in my main method is taken from the HDF samples, and looks like this:

H5File h5file = new
H5File("C:\\dev\\workspaces\\hdf5\\hdf5\\src\\main\\java\\com\\vaisala\\hdf5\\hdf5_test.h5",
HDF5Constants.H5F_ACC_RDONLY);

        try
        {
            // open file and retrieve the file structure
            h5file.open();
        }
        catch (Exception ex)
        {
            System.out.println(ex);
        }

When I run it, it throws the following exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError:
ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(ILjava/lang/String;[Ljava/lang/String;[I[JI)I
at ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(Native Method)
at ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(H5.java:4588)
at ncsa.hdf.object.h5.H5File.depth_first(H5File.java:1617)
at ncsa.hdf.object.h5.H5File.loadTree(H5File.java:1554)
at ncsa.hdf.object.h5.H5File.open(H5File.java:1520)
at ncsa.hdf.object.h5.H5File.open(H5File.java:1464)
at ncsa.hdf.object.h5.H5File.open(H5File.java:825)
at com.vaisala.hdf5.TestH5File.main(TestH5File.java:24)

Any ideas what could be wrong?

Marko Kurm

It may be the dependencies such as the hdf5 native libraries aren't being found by the path.

While debugging beforecalling H5File I put in code loading the jhdf5.dll by load instead of the production way loadLibrary:

.....
//System.loadLibrary("jhdf5");
System.load("<full local path to lib>jhdf5.dll");
....
where <full local path to lib> is c:\NetBeansProjects\hdf5\lib\

If it can't find something, this development style will spit out what can't be found

···

On 05/14/2013 09:52 AM, Marko Kurm wrote:

I'm trying to open/read an existing HDF5 file using the Java library. I have the "jhdf.dll" and "jhdf5.dll" files on the system path. The code I have in my main method is taken from the HDF samples, and looks like this:

H5File h5file = new H5File("C:\\dev\\workspaces\\hdf5\\hdf5\\src\\main\\java\\com\\vaisala\\hdf5\\hdf5_test.h5", HDF5Constants.H5F_ACC_RDONLY);

        try
        {
            // open file and retrieve the file structure
            h5file.open();
        }
        catch (Exception ex)
        {
            System.out.println(ex);
        }

When I run it, it throws the following exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(ILjava/lang/String;[Ljava/lang/String;[I[JI)I
at ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(Native Method)
at ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(H5.java:4588)
at ncsa.hdf.object.h5.H5File.depth_first(H5File.java:1617)
at ncsa.hdf.object.h5.H5File.loadTree(H5File.java:1554)
at ncsa.hdf.object.h5.H5File.open(H5File.java:1520)
at ncsa.hdf.object.h5.H5File.open(H5File.java:1464)
at ncsa.hdf.object.h5.H5File.open(H5File.java:825)
at com.vaisala.hdf5.TestH5File.main(TestH5File.java:24)

Any ideas what could be wrong?

Marko Kurm

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

you need to set the HDF library path.

If you are running your application from your script, add the library to the command line, e.g.
java -Djava.library.path=%PATH_TO_THE_DLLS% ...

If you are running with eclipse, set VM argument, -Djava.library.path=%PATH_TO_THE_DLLS%
under run->Run Configurations->Arguments

···

On 5/14/2013 8:52 AM, Marko Kurm wrote:

I'm trying to open/read an existing HDF5 file using the Java library. I have the "jhdf.dll" and "jhdf5.dll" files on the system path. The code I have in my main method is taken from the HDF samples, and looks like this:

H5File h5file = new H5File("C:\\dev\\workspaces\\hdf5\\hdf5\\src\\main\\java\\com\\vaisala\\hdf5\\hdf5_test.h5", HDF5Constants.H5F_ACC_RDONLY);

        try
        {
            // open file and retrieve the file structure
            h5file.open();
        }
        catch (Exception ex)
        {
            System.out.println(ex);
        }

When I run it, it throws the following exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(ILjava/lang/String;[Ljava/lang/String;[I[JI)I
at ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(Native Method)
at ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(H5.java:4588)
at ncsa.hdf.object.h5.H5File.depth_first(H5File.java:1617)
at ncsa.hdf.object.h5.H5File.loadTree(H5File.java:1554)
at ncsa.hdf.object.h5.H5File.open(H5File.java:1520)
at ncsa.hdf.object.h5.H5File.open(H5File.java:1464)
at ncsa.hdf.object.h5.H5File.open(H5File.java:825)
at com.vaisala.hdf5.TestH5File.main(TestH5File.java:24)

Any ideas what could be wrong?

Marko Kurm

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Maybe need to be in a static scope to get it to happen earlier than the H5 one

example from a linux case I was debugging

..............
         static
         {
             try {
                 //System.loadLibrary("jqb");
                 //System.load(System.getProperty("QB_HOME")+"/lib/libjqb.so");
                 //System.load("/home/roger/NetBeansProjects/jhdf5hl/dist/libjhdf5hl.so");
                 //System.load("/home/roger/Software/hdf5-1.8.5/dist/lib/libhdf5_hl.so");
                 //System.load("/home/roger/Software/hdf5-1.8.5/dist/lib/libhdf5.so");
                 //System.load("/home/roger/Software/openmpi-1.4.3/dist/lib/libmpi.so");
                 //System.load("/home/roger/Software/openmpi-1.4.3/dist/lib/libmpi_cxx.so");
                 //System.loadLibrary("mpi");
                 System.loadLibrary("open-rte");
                 System.loadLibrary("open-pal");
                 System.loadLibrary("mpi");
                 System.loadLibrary("hdf5");
                 System.loadLibrary("hdf5_hl");
                 System.loadLibrary("jhdf5");
                 //System.loadLibrary("mpi_cxx");
                 H5.H5open();
                 //H5.
             } catch (UnsatisfiedLinkError e) {
                 System.err.println("Native code library failed to load. Unsatisfied Link Error\n" + e);
             } catch (Exception e) {
                 System.err.println("Native code library failed to load. \n" + e);
             }
         int plist = HDF5Constants.H5P_DEFAULT;
         int[] version_info = new int[4];
         try {
             H5.H5Pget_version(plist,version_info);
         } catch (Exception ex) {
         }
..............

where I open the commented System.load's to test

···

On 05/14/2013 09:52 AM, Marko Kurm wrote:

I'm trying to open/read an existing HDF5 file using the Java library. I have the "jhdf.dll" and "jhdf5.dll" files on the system path. The code I have in my main method is taken from the HDF samples, and looks like this:

H5File h5file = new H5File("C:\\dev\\workspaces\\hdf5\\hdf5\\src\\main\\java\\com\\vaisala\\hdf5\\hdf5_test.h5", HDF5Constants.H5F_ACC_RDONLY);

        try
        {
            // open file and retrieve the file structure
            h5file.open();
        }
        catch (Exception ex)
        {
            System.out.println(ex);
        }

When I run it, it throws the following exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(ILjava/lang/String;[Ljava/lang/String;[I[JI)I
at ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(Native Method)
at ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(H5.java:4588)
at ncsa.hdf.object.h5.H5File.depth_first(H5File.java:1617)
at ncsa.hdf.object.h5.H5File.loadTree(H5File.java:1554)
at ncsa.hdf.object.h5.H5File.open(H5File.java:1520)
at ncsa.hdf.object.h5.H5File.open(H5File.java:1464)
at ncsa.hdf.object.h5.H5File.open(H5File.java:825)
at com.vaisala.hdf5.TestH5File.main(TestH5File.java:24)

Any ideas what could be wrong?

Marko Kurm

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Thanks for the help guys!I have the DLL files in the system path + I added
the following arguments to the run
configuration:-Djava.library.path=C:/dev/hdf5/hdf-java/lib/win-Dncsa.hdf.hdf5lib.H5.hdf5lib=C:/dev/hdf5/hdf-java/lib/win/jhdf5.dlland
inside C:/dev/hdf5/hdf-java/lib/win folder, I have two files: jhdf5.dll &
jhdf.dll. At first I had the problem that the DLL-s where not on the path,
but in that case, it throws a "java.lang.UnsatisfiedLinkError: no jhdf5 in
java.library.path" exception so this is not the case.Anyway, I still get the
same error message: Exception in thread "main"
java.lang.UnsatisfiedLinkError:
ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(ILjava/lang/String;[Ljava/lang/String;[I[JI)II
took a look inside the DLL-s (with DLL Export Viewer
<http://www.nirsoft.net/utils/dll_export_viewer.html> ) to see what
functions they export and I didn't see the "H5Gget_obj_info_all" function
there. Maybe I'm missing some DLL? I only have the two that came with
downloading this file
<http://www.hdfgroup.org/ftp/HDF5/hdf-java/bin/win64/hdf-java-2.9-bin.tar>
What kind of HDF DLL-s do you have on your paths?

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/Reading-an-HDF5-file-in-Java-tp4026180p4026189.html
Sent from the hdf-forum mailing list archive at Nabble.com.

Sorry, the formatting didn't work. Here it is again:

I have the DLL files in the system path + I added the following arguments
to the run configuration:

-Djava.library.path=C:/dev/hdf5/hdf-java/lib/win
-Dncsa.hdf.hdf5lib.H5.hdf5lib=C:/dev/hdf5/hdf-java/lib/win/jhdf5.dll

and inside C:/dev/hdf5/hdf-java/lib/win folder, I have two files: jhdf5.dll
& jhdf.dll. At first I had the problem that the DLL-s where not on the
path, but in that case, it throws a "java.lang.UnsatisfiedLinkError: no
jhdf5 in java.library.path" exception so this is not the case. Anyway, I
still get the same error message: Exception in thread "main"
java.lang.UnsatisfiedLinkError:
ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(ILjava/lang/
String;[Ljava/lang/String;[I[JI)I

I took a look inside the DLL-s (with DLL Export
Viewer<http://www.nirsoft.net/utils/dll_export_viewer.html>)
to see what functions they export and I didn't see the
"H5Gget_obj_info_all" function there. Maybe I'm missing some DLL? I only
have the two that came with downloading this
file<http://www.hdfgroup.org/ftp/HDF5/hdf-java/bin/win64/hdf-java-2.9-bin.tar>
What
kind of HDF DLL-s do you have on your paths?

···

2013/5/16 marko.kurm <marko.kurm@gmail.com>

Thanks for the help guys! I have the DLL files in the system path + I
added the following arguments to the run configuration:
-Djava.library.path=C:/dev/hdf5/hdf-java/lib/win
-Dncsa.hdf.hdf5lib.H5.hdf5lib=C:/dev/hdf5/hdf-java/lib/win/jhdf5.dll and
inside C:/dev/hdf5/hdf-java/lib/win folder, I have two files: jhdf5.dll &
jhdf.dll. At first I had the problem that the DLL-s where not on the path,
but in that case, it throws a "java.lang.UnsatisfiedLinkError: no jhdf5 in
java.library.path" exception so this is not the case. Anyway, I still get
the same error message: Exception in thread "main"
java.lang.UnsatisfiedLinkError:
ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(ILjava/lang/String;[Ljava/lang/String;[I[JI)I
I took a look inside the DLL-s (with DLL Export Viewer<http://www.nirsoft.net/utils/dll_export_viewer.html>)
to see what functions they export and I didn't see the
"H5Gget_obj_info_all" function there. Maybe I'm missing some DLL? I only
have the two that came with downloading this file<http://www.hdfgroup.org/ftp/HDF5/hdf-java/bin/win64/hdf-java-2.9-bin.tar>What kind of HDF DLL-s do you have on your paths?
------------------------------
View this message in context: Re: Reading an HDF5 file in Java<http://hdf-forum.184993.n3.nabble.com/Reading-an-HDF5-file-in-Java-tp4026180p4026189.html>
Sent from the hdf-forum mailing list archive<http://hdf-forum.184993.n3.nabble.com/>at Nabble.com.

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Peter is referring to the HDF5 libs; not just the java native interface ones (e.g. jhdf5)
The ones of HDF5 itself as in hdf5.dll and hdf5_hl.dll etc. jhdf5.dll & jhdf.dll are only the native glue

System.load("<full path to libs</ jhdf.dll");
will show what is needed clearly

···

On 05/16/2013 03:10 AM, Marko Kurm wrote:

Sorry, the formatting didn't work. Here it is again:

I have the DLL files in the system path + I added the following arguments to the run configuration:

-Djava.library.path=C:/dev/hdf5/hdf-java/lib/win
-Dncsa.hdf.hdf5lib.H5.hdf5lib=C:/dev/hdf5/hdf-java/lib/win/jhdf5.dll

and inside C:/dev/hdf5/hdf-java/lib/win folder, I have two files: jhdf5.dll & jhdf.dll. At first I had the problem that the DLL-s where not on the path, but in that case, it throws a "java.lang.UnsatisfiedLinkError: no jhdf5 in java.library.path" exception so this is not the case. Anyway, I still get the same error message: Exception in thread "main" java.lang.UnsatisfiedLinkError: ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(ILjava/lang/String;[Ljava/lang/String;[I[JI)I

I took a look inside the DLL-s (with DLL Export Viewer <http://www.nirsoft.net/utils/dll_export_viewer.html>) to see what functions they export and I didn't see the "H5Gget_obj_info_all" function there. Maybe I'm missing some DLL? I only have the two that came with downloading this file <http://www.hdfgroup.org/ftp/HDF5/hdf-java/bin/win64/hdf-java-2.9-bin.tar> What kind of HDF DLL-s do you have on your paths?

2013/5/16 marko.kurm <marko.kurm@gmail.com <mailto:marko.kurm@gmail.com>>

    Thanks for the help guys! I have the DLL files in the system path
    + I added the following arguments to the run configuration:
    -Djava.library.path=C:/dev/hdf5/hdf-java/lib/win
    -Dncsa.hdf.hdf5lib.H5.hdf5lib=C:/dev/hdf5/hdf-java/lib/win/jhdf5.dll
    and inside C:/dev/hdf5/hdf-java/lib/win folder, I have two files:
    jhdf5.dll & jhdf.dll. At first I had the problem that the DLL-s
    where not on the path, but in that case, it throws a
    "java.lang.UnsatisfiedLinkError: no jhdf5 in java.library.path"
    exception so this is not the case. Anyway, I still get the same
    error message: Exception in thread "main"
    java.lang.UnsatisfiedLinkError:
    ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(ILjava/lang/String;[Ljava/lang/String;[I[JI)I
    I took a look inside the DLL-s (with DLL Export Viewer
    <http://www.nirsoft.net/utils/dll_export_viewer.html>) to see what
    functions they export and I didn't see the "H5Gget_obj_info_all"
    function there. Maybe I'm missing some DLL? I only have the two
    that came with downloading this file
    <http://www.hdfgroup.org/ftp/HDF5/hdf-java/bin/win64/hdf-java-2.9-bin.tar>
    What kind of HDF DLL-s do you have on your paths?
    ------------------------------------------------------------------------
    View this message in context: Re: Reading an HDF5 file in Java
    <http://hdf-forum.184993.n3.nabble.com/Reading-an-HDF5-file-in-Java-tp4026180p4026189.html>
    Sent from the hdf-forum mailing list archive
    <http://hdf-forum.184993.n3.nabble.com/> at Nabble.com.

    _______________________________________________
    Hdf-forum is for HDF software users discussion.
    Hdf-forum@hdfgroup.org <mailto:Hdf-forum@hdfgroup.org>
    http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Ok, didn't realize that. Thanks! Now I downloaded the actual HDF5 library and
installed it. I added the following to the VM arguments:
-Djava.library.path="C:\Program Files\HDF_Group\HDF5\1.8.11\bin" ( this is
where the DLLs are).

And at least this code runs through without exceptions:

System.loadLibrary("hdf5");
System.loadLibrary("hdf5_hl");
System.loadLibrary("jhdf5");

So it seems that the libraries are loaded at least. But when I run the
following, I still get the same exception (java.lang.UnsatisfiedLinkError:
ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(ILjava/lang/String;[Ljava/lang/String;[I[JI)I):

H5File h5file = new
H5File("C:\\dev\\workspaces\\hdf5\\hdf5\\src\\main\\java\\com\\vaisala\\hdf5\\hdf5_test.h5",
HDF5Constants.H5F_ACC_RDONLY);
h5file.open();
h5file.close();

Is there something I could still try?

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/Reading-an-HDF5-file-in-Java-tp4026180p4026196.html
Sent from the hdf-forum mailing list archive at Nabble.com.

You have to use the HDF5 JNI libray, which was built with Java JNI and
the HDF5 C library.

You can find the instructions for installing and using HDF-Java at
http://www.hdfgroup.org/hdf-java-html/install_use_hdf_java_products.pdf

Thanks
--pc

···

On 5/17/2013 1:44 AM, marko.kurm wrote:

Ok, didn't realize that. Thanks! Now I downloaded the actual HDF5 library and
installed it. I added the following to the VM arguments:
-Djava.library.path="C:\Program Files\HDF_Group\HDF5\1.8.11\bin" ( this is
where the DLLs are).

And at least this code runs through without exceptions:

System.loadLibrary("hdf5");
System.loadLibrary("hdf5_hl");
System.loadLibrary("jhdf5");

So it seems that the libraries are loaded at least. But when I run the
following, I still get the same exception (java.lang.UnsatisfiedLinkError:
ncsa.hdf.hdf5lib.H5.H5Gget_obj_info_all(ILjava/lang/String;[Ljava/lang/String;[I[JI)I):

H5File h5file = new
H5File("C:\\dev\\workspaces\\hdf5\\hdf5\\src\\main\\java\\com\\vaisala\\hdf5\\hdf5_test.h5",
HDF5Constants.H5F_ACC_RDONLY);
h5file.open();
h5file.close();

Is there something I could still try?

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/Reading-an-HDF5-file-in-Java-tp4026180p4026196.html
Sent from the hdf-forum mailing list archive at Nabble.com.

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org