hadoop抱怨不存在匿名类(noclassdeffounderror)

zyfwsgd6  于 2021-05-31  发布在  Hadoop
关注(0)|答案(1)|浏览(339)

考虑一个简单的java文件,它创建一个 BufferedInputStream 复制本地文件 1400-8.txt 到hadoop hdfs并打印一些点作为进度状态。这个例子是hadoop书中的例子3-3。

  1. // cc FileCopyWithProgress Copies a local file to a Hadoop filesystem, and shows progress
  2. import java.io.BufferedInputStream;
  3. import java.io.FileInputStream;
  4. import java.io.InputStream;
  5. import java.io.OutputStream;
  6. import java.net.URI;
  7. import org.apache.hadoop.conf.Configuration;
  8. import org.apache.hadoop.fs.FileSystem;
  9. import org.apache.hadoop.fs.Path;
  10. import org.apache.hadoop.io.IOUtils;
  11. import org.apache.hadoop.util.Progressable;
  12. // vv FileCopyWithProgress
  13. public class FileCopyWithProgress {
  14. public static void main(String[] args) throws Exception {
  15. String localSrc = args[0];
  16. String dst = args[1];
  17. InputStream in = new BufferedInputStream(new FileInputStream(localSrc));
  18. Configuration conf = new Configuration();
  19. FileSystem fs = FileSystem.get(URI.create(dst), conf);
  20. OutputStream out = fs.create(new Path(dst), new Progressable() {
  21. public void progress() {
  22. System.out.print(".");
  23. }
  24. });
  25. IOUtils.copyBytes(in, out, 4096, true);
  26. }
  27. }
  28. // ^^ FileCopyWithProgress

我编译代码并用

  1. hadoop com.sun.tools.javac.Main FileCopyWithProgress.java
  2. jar cf FileCopyWithProgress.jar FileCopyWithProgress.class

以上命令生成文件 FileCopyWithProgress.class , FileCopyWithProgress$1.class 以及 FileCopyWithProgress.jar . 然后,我试着运行它

  1. 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 是由于程序声明的匿名回调函数。但是既然文件存在,这里的问题是什么?我是否运行了正确的命令序列?

pb3skfrl

pb3skfrl1#

我发现的问题,所以我只是张贴的情况下,它有助于某人。我得把班级也包括进去 FileCopyWithProgress$1.class 在jar里。正确的应该是

  1. jar cf FileCopyWithProgress.jar FileCopyWithProgress*.class

相关问题