首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hadoop抱怨不存在的匿名类(NoClassDefFoundError)

Hadoop抱怨不存在的匿名类(NoClassDefFoundError)
EN

Stack Overflow用户
提问于 2020-08-14 04:19:53
回答 1查看 64关注 0票数 0

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

代码语言:javascript
复制
// 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文件

代码语言:javascript
复制
hadoop com.sun.tools.javac.Main FileCopyWithProgress.java
jar cf FileCopyWithProgress.jar FileCopyWithProgress.class

上面的命令生成文件FileCopyWithProgress.classFileCopyWithProgress$1.classFileCopyWithProgress.jar。然后,我试着运行它

代码语言:javascript
复制
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是由程序声明的匿名回调函数造成的。但是由于文件存在,这里有什么问题?我是否运行了正确的命令序列?

EN

回答 1

Stack Overflow用户

发布于 2020-08-14 05:44:43

我发现了问题,所以我只是张贴,以防万一它对某人有帮助。我必须在JAR中包含类FileCopyWithProgress$1.class。正确的应该是

代码语言:javascript
复制
jar cf FileCopyWithProgress.jar FileCopyWithProgress*.class
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63406495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档