Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取ClassNotFound异常:在Hadoop中转储配置时_Hadoop - Fatal编程技术网

获取ClassNotFound异常:在Hadoop中转储配置时

获取ClassNotFound异常:在Hadoop中转储配置时,hadoop,Hadoop,我正在尝试“hadoop in Action”一书中的一个简单程序,将本地文件系统中的一系列文件合并到hdfs中的一个文件中。代码片段与本书中提供的代码片段相同 import java.lang.*; import java.util.*; import java.io.*; import org.apache.hadoop.fs.*; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileStatus;

我正在尝试“hadoop in Action”一书中的一个简单程序,将本地文件系统中的一系列文件合并到hdfs中的一个文件中。代码片段与本书中提供的代码片段相同

import java.lang.*;
import java.util.*;
import java.io.*;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path;

public class PutMerge {

    public static void main(String[] args) throws IOException{
        Configuration conf = new Configuration();
        FileSystem hdfs = FileSystem.get(conf);
        FileSystem local = FileSystem.getLocal(conf);

        Path inputDir = new Path(args[0]); // First argument has the input directory 
        Path hdfsFile = new Path(args[1]); // Concatenated hdfs file name

        try {
            FileStatus[] inputFiles = local.listStatus(inputDir); // list of Local Files

            FSDataOutputStream out = hdfs.create(hdfsFile); // target file creation

            for (int i = 0; i<inputFiles.size; i++ {

                FSDataInputStream in = local.open(inputFiles[i].getPath());

                int bytesRead = 0;
                byte[] buff = new byte[256];

                while (bytesRead = (in.read(buff))>0) {
                    out.write(buff,0,bytesRead);
                }
                in.close();
            }
            out.close();

        } 
        catch(Exception e) {
            e.printStackTrace();
        }

    }
}
有什么线索可以解释为什么这不起作用吗?

您没有将其包含在类路径中

实际上,除了hadoop本身,您不需要包含太多内容。确保使用hadoop本身运行jar

hadoop-jarmyjar.jar

/usr/java/jdk1.7.0_21:/data/commons-logging-1.1.2/commons-logging-1.1.2.jar:/data/hadoop-1.1.2/hadoop-core-1.1.2.jar:/data/commons-logging-1.1.2/commons-logging-adapters-1.1.2.jar:/data/commons-logging-1.1.2/commons-logging-api-1.1.2.jar:.