考虑一个简单的java文件,它创建一个 BufferedInputStream
复制本地文件 1400-8.txt
到hadoop hdfs并打印一些点作为进度状态。这个例子是hadoop书中的例子3-3。
// cc FileCopyWithProgress Copies a local file to a Hadoop filesystem, and shows progress
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.util.Progressable;
// vv FileCopyWithProgress
public class FileCopyWithProgress {
public static void main(String[] args) throws Exception {
String localSrc = args[0];
String dst = args[1];
InputStream in = new BufferedInputStream(new FileInputStream(localSrc));
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(dst), conf);
OutputStream out = fs.create(new Path(dst), new Progressable() {
public void progress() {
System.out.print(".");
}
});
IOUtils.copyBytes(in, out, 4096, true);
}
}
// ^^ FileCopyWithProgress
我编译代码并用
hadoop com.sun.tools.javac.Main FileCopyWithProgress.java
jar cf FileCopyWithProgress.jar FileCopyWithProgress.class
以上命令生成文件 FileCopyWithProgress.class
, FileCopyWithProgress$1.class
以及 FileCopyWithProgress.jar
. 然后,我试着运行它
hadoop jar FileCopyWithProgress.jar FileCopyWithProgress 1400-8.txt hdfs://localhost:9000/user/kostas/1400-8.txt
但是,我收到了错误
线程“main”java.lang.noclassdeffounderror中出现异常:filecopywithprogress$1
据我所知 FileCopyWithProgress$1.class
是由于程序声明的匿名回调函数。但是既然文件存在,这里的问题是什么?我是否运行了正确的命令序列?
1条答案
按热度按时间pb3skfrl1#
我发现的问题,所以我只是张贴的情况下,它有助于某人。我得把班级也包括进去
FileCopyWithProgress$1.class
在jar里。正确的应该是