java使用hdf.jar,hdf5在maven项目中

I'm trying to import hdf.hdf5lib.H5 into my maven project in NetBeans. It has this as import line

import hdf.hdf5lib.H5;

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:

org.hdfgroup

hdf-java

2.6.1

jar

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:

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.

In Maven project open "Add dependency" dialog

Make up some groupId, artifactId and version and fill them, OK.

Dependency will be added to the pom.xml and will appear under "Libraries" node of maven project

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).

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.(H5.java:230)

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值