Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing files in hdfs in C++ (libhdfs)

I am trying to write an interface in C++ to write files in hdfs using libhdfs.so. My target hadoop version is 2.0.2-alpha

The below code

 hdfsFS fs = hdfsConnect("127.0.0.1",8020);
 if (!fs)
 {
    printf("Hadoop file system returned null. \n");
    return 0;
 }

provides the following error while running:

Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object

Updated the CLASSPATH accordingly but still getting this error. Any idea what is the step I am missing here? All the .so files are linked correctly.

like image 309
user2690713 Avatar asked Aug 16 '13 20:08

user2690713


1 Answers

You can use following command to find the java classpath needed by hadoop

$hadoop classpath

And add all of these paths to environment variable CLASSPATH

$export CLASSPATH=$CLASSPATH:`hadoop classpath`

Here is a example of libhdfs for CDH4. Notice the environment settings in exec.sh

like image 59
RabitChang Avatar answered Oct 21 '22 16:10

RabitChang