Friday, December 22, 2017

hdf5 in maven project

Leave a Comment

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?

As suggested by ddarellis this might be a version problem. It seems there are two options.

  • HDF Java 3.3.2, and HDF5-1.8.19 (HDFView Version 2.14)
  • Java HDF Object Package 3.0.0, and HDF5-1.10

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

  1. In Maven project open "Add dependency" dialog
  2. Make up some groupId, artifactId and version and fill them, OK.
  3. Dependency will be added to the pom.xml and will appear under "Libraries" node of maven project
  4. Right-click Lib node and "manually install artifact", fill the path to the jar Jar should be installed to local Maven repo with coordinates entered in step 2).

2 Answers

Answers 1

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.

Answers 2

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.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment