考虑一个简单的Java文件,它创建一个BufferedInputStream将本地文件1400-8.txt复制到Hadoop,并打印一些点作为进度状态。该示例是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我编译代码并创建JAR文件
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是由程序声明的匿名回调函数造成的。但是由于文件存在,这里有什么问题?我是否运行了正确的命令序列?
发布于 2020-08-14 05:44:43
我发现了问题,所以我只是张贴,以防万一它对某人有帮助。我必须在JAR中包含类FileCopyWithProgress$1.class。正确的应该是
jar cf FileCopyWithProgress.jar FileCopyWithProgress*.classhttps://stackoverflow.com/questions/63406495
复制相似问题