首先,我使用正確設置的mvn和環境變量構建了hadoop-2.7.2。然後我試圖在Apache網站運行簡單的例子:C API libhdfs example code當在hdfs中調用hdfsOpenFile時,Hadoop異常java.lang.NoSuchMethodError C API
#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/Progressable;Z)Lorg/apache/hadoop/fs/FSDataOutputStream;
$ Exception in thread "main" java.lang.NoSuchMethodError: create
$ Call to org.apache.hadoop.conf.FileSystem::create((Lorg/apache/hadoop/fs/Path;Lorg/apache/hadoop/fs/permission/FsPermission;ZISJILorg/apache/hadoop/util/Progressable;Z)Lorg/apache/hadoop/fs/FSDataOutputStream;) failed!
但我可以在組織找到「創建」功能.apache.hadoop.fs.FileSystem: org.apache.hadoop.fs.FileSystem function list
任何人都知道發生了什麼?