首先,我使用mvn和正确设置的环境变量构建了hadoop-2.7.2。然后,我尝试在apache网站上运行一个简单的示例:c api libhdfs示例代码
# include "hdfs.h"
int main(int argc, char**argv) {
hdfsFS fs = hdfsConnect("default", 0);
const char* writePath = "/tmp/testfile.txt";
hdfsFile writeFile = hdfsOpenFile(fs, writePath, O_WRONLY |O_CREAT, 0, 0, 0);
if(!writeFile) {
fprintf(stderr, "Failed to open %s for writing!\n", writePath);
exit(-1);
}
char* buffer = "Hello, World!";
tSize num_written_bytes = hdfsWrite(fs, writeFile, (void*)buffer, strlen(buffer)+1);
if (hdfsFlush(fs, writeFile)) {
fprintf(stderr, "Failed to 'flush' %s\n", writePath);
exit(-1);
}
hdfsCloseFile(fs, writeFile);
}
然后我得到如下错误信息:
$could not find method create from class org/apache/hadoop/fs/filesystem with signature(lorg/apache/hadoop/fs/path;lorg/apache/hadoop/fs/permission/fspermission;zisjilorg/apache/hadoop/util/progressible;z) lorg/apache/hadoop/fs/fsdataoutputstream;
线程“main”java.lang.nosuchmethoderror中的$exception:创建
$call to org.apache.hadoop.conf.filesystem::create((lorg/apache/hadoop/fs/path;lorg/apache/hadoop/fs/permission/fspermission;zisjilorg/apache/hadoop/util/progressible;z) lorg/apache/hadoop/fs/fsdataoutputstream;)失败!
但是我确实可以在org.apache.hadoop.fs.filesystem:org.apache.hadoop.fs.filesystem函数列表中找到“create”函数
有人知道发生了什么吗?
1条答案
按热度按时间68de4m5k1#
我不得不承认我的愚蠢问题。我在链接定义中包含了一个错误的依赖项。所以我的程序试图从另一个库中调用错误的create()。。。现在我可以使用所有开源的hdfsapi了。