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
Hadoop自定义Java程序_Hadoop_Jar_Classnotfoundexception - Fatal编程技术网

Hadoop自定义Java程序

Hadoop自定义Java程序,hadoop,jar,classnotfoundexception,Hadoop,Jar,Classnotfoundexception,我有一个名为putmerge的简单java程序,我正在尝试执行它。我已经做了6个小时了,在网上搜索了很多地方,但没有找到解决办法。基本上,我尝试使用以下命令使用所有类库构建jar: javac -classpath *:lib/* -d playground/classes playground/src/PutMerge.java bin/hadoop jar playground/putmerge.jar org.scd.putmerge "..inputPath.." "..outPath

我有一个名为putmerge的简单java程序,我正在尝试执行它。我已经做了6个小时了,在网上搜索了很多地方,但没有找到解决办法。基本上,我尝试使用以下命令使用所有类库构建jar:

javac -classpath *:lib/* -d playground/classes playground/src/PutMerge.java
bin/hadoop jar playground/putmerge.jar org.scd.putmerge "..inputPath.." "..outPath"
然后我用下面的命令构建jar

jar -cvf playground/putmerge.jar -C playground/classes/ .
然后我尝试用以下命令执行它:

javac -classpath *:lib/* -d playground/classes playground/src/PutMerge.java
bin/hadoop jar playground/putmerge.jar org.scd.putmerge "..inputPath.." "..outPath"

我尝试了每一种排列/组合来运行这个简单的jar,但是我总是遇到一些异常,如上图所示

我的源代码:

package org.scd.putmerge;

import java.io.IOException;
import java.util.Scanner;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;

import org.apache.hadoop.fs.Path;

/**
 * 
 * @author Anup V. Saumithri
 *
 */
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]);
        Path hdfsFile = new Path(args[1]);



        try
        {
            FileStatus[] inputFiles = local.listStatus(inputDir);
            FSDataOutputStream out = hdfs.create(hdfsFile);

            for(int i=0; i<inputFiles.length; i++)
            {
                System.out.println(inputFiles[i].getPath().getName());
                FSDataInputStream in = local.open(inputFiles[i].getPath());

                byte buffer[] = new byte[256];
                int bytesRead = 0;
                while((bytesRead = in.read(buffer)) > 0)
                {
                    out.write(buffer, 0, bytesRead);
                }
                in.close();
            }
            out.close();
        }
        catch(IOException ex)
        {
            ex.printStackTrace();
        }   
    }
}
package org.scd.putmerge;
导入java.io.IOException;
导入java.util.Scanner;
导入org.apache.hadoop.conf.Configuration;
导入org.apache.hadoop.fs.FSDataInputStream;
导入org.apache.hadoop.fs.FSDataOutputStream;
导入org.apache.hadoop.fs.FileStatus;
导入org.apache.hadoop.fs.FileSystem;
导入org.apache.hadoop.fs.Path;
/**
* 
*@作者Anup V.Saumithri
*
*/
公共类合并
{
公共静态void main(字符串[]args)引发IOException
{
Configuration conf=新配置();
FileSystem hdfs=FileSystem.get(conf);
FileSystem local=FileSystem.getLocal(conf);
路径inputDir=新路径(args[0]);
路径hdfsFile=新路径(args[1]);
尝试
{
FileStatus[]inputFiles=local.listStatus(inputDir);
FSDataOutputStream out=hdfs.create(hdfsFile);
对于(int i=0;i 0)
{
out.write(缓冲区,0,字节读取);
}
in.close();
}
out.close();
}
捕获(IOEX异常)
{
例如printStackTrace();
}   
}
}

将PutMerge类放入jar的方式可能有点不正确

如果执行
jar tf putmerge.jar
,则必须在代码(即org/scd/putmerge)中的包(org.scd.putmerge)中提到的路径中看到putmerge类

如果没有,请尝试执行以下操作以实现此目的。确保已将PutMerge.class复制到org/scd/PutMerge/目录中

jar -cvf playground/putmerge.jar org/scd/putmerge/PutMerge.class
接下来,用
jar tf putmerge.jar
再次验证,以检查现在是否在输出中看到
org/scd/putmerge/putmerge.clas
s

如果一切正常,您可以尝试再次运行hadoop jar。但是看看这些错误,我发现您实际上没有将PutMerge类包含在包中。您应该使用org.scd.putmerge.putmerge。所以,正确的方法应该是--


明亮的这解决了我的问题。非常感谢。对于记录,问题在于bin/hadoop jar命令中的包规范。我把它改成了org.scd.putmerge.putmerge,正如你上面提到的。。。。。。它开始工作了。。。。