0

Firstly I had the hadoop-2.7.2 built using mvn and environment variables set correctly. Then I'm trying to run the simple example on Apache website: C API libhdfs example code

#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);
}

Then I got the error message as below:

$ 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!

But I do can find the 'create' function in org.apache.hadoop.fs.FileSystem: org.apache.hadoop.fs.FileSystem function list

Anyone have idea what's happening?

Community
  • 1
  • 1

1 Answers1

0

I have to admit my silly question here. I included a wrong dependency in my linking definition. So my program is trying to call a wrong create() from another library... Now I'm able to use all the open sourced hdfs API now.