hdf5在maven项目中 [英] hdf5 in maven project
问题描述
我正在尝试将hdf.hdf5lib.H5导入到NetBeans中的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;
如下所示: 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已警告过我关于它,在进口线说packadge不要激动。所以我让它搜索Maven存储库中的依赖项。它确实找到了一些内容并将其添加到我的pom.xml中:
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>
不幸的是,它会在导入行packadge不会激活和错误异常时发出警告。似乎pom.xml的这个补充什么也没做。
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.
我是所有这些的初学者,所以也许解决方案很明显,但我找不到它。这些问题可以追溯到2012年至2014年,但对我没有帮助:
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
添加hdf5库(java) & c ++)到公共maven存储库?
如何在带有NetBeans的Windows Java项目中使用HDF5
根据ddarellis的建议,这可能是版本问题。似乎有两种选择。
As suggested by ddarellis this might be a version problem. It seems there are two options.
- HDF Java 3.3.2和HDF5-1.8.19(HDFView版本2.14)
- Java HDF对象包3.0.0和HDF5-1.10
我会尝试两者,但maven建议使用HDF Java 2.6.1是错误的。
I'll try both, but the suggestion from maven to use HDF Java 2.6.1 is wrong.
这篇文章有助于将jarhdf5-3.3.2.jar添加到依赖项中。
This post was helpfull for adding jarhdf5-3.3.2.jar to the dependencies.
https://forums.netbeans.org/post-62903.html#62903
- 在Maven项目中打开添加依赖关系对话框
- 组成一些groupId ,artifactId和版本并填充它们,好的。
- 依赖关系将被添加到pom.xml,并将显示在maven项目的Libraries节点下
- 右键单击Lib节点并手动安装工件,填充jar的路径Jar应安装到本地Maven仓库,并在步骤2中输入坐标。)
- 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).
好的,所以我安装了HDF5 1.8.19 HDFView2.14并将jarhdf5-3.3.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.<clinit>(H5.java:230)
推荐答案
The link you refer to contains out-of-date examples, you should use these examples instead.
正如 ddarellis 所指出的,正确的包装是:
As pointed by ddarellis, the correct package is:
ncsa.hdf.hdf5lib
以下是打开HDF5文件的工作示例:
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");
}
}
}
maven您拥有的依赖关系是正确的,并且是 maven central 上的最新版本。
The maven dependency you have is correct and is the latest available on maven central.
这篇关于hdf5在maven项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!