gpt4 book ai didi

hadoop - 获取ClassNotFound异常:在Hadoop中转储配置时

转载 作者:行者123 更新时间:2023-12-02 20:10:24 25 4
gpt4 key购买 nike

我正在尝试从“hadoop in Action”一书中找到一个简单的程序,以将来自本地文件系统的一系列文件合并为hdfs中的一个文件。该代码段与本书中提供的代码段相同。

import java.lang.*;
import java.util.*;
import java.io.*;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path;

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]); // First argument has the input directory
Path hdfsFile = new Path(args[1]); // Concatenated hdfs file name

try {
FileStatus[] inputFiles = local.listStatus(inputDir); // list of Local Files

FSDataOutputStream out = hdfs.create(hdfsFile); // target file creation

for (int i = 0; i<inputFiles.size; i++ {

FSDataInputStream in = local.open(inputFiles[i].getPath());

int bytesRead = 0;
byte[] buff = new byte[256];

while (bytesRead = (in.read(buff))>0) {
out.write(buff,0,bytesRead);
}
in.close();
}
out.close();

}
catch(Exception e) {
e.printStackTrace();
}

}
}

该程序已成功编译,并且在尝试运行时出现以下异常

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/configuration/Configuration at org.apache.hadoop.metrics2.lib.DefaultMetricsSystem.(DefaultMetricsSystem.java:37) at org.apache.hadoop.metrics2.lib.DefaultMetricsSystem.(DefaultMetricsSystem.java:34) at org.apache.hadoop.security.UgiInstrumentation.create(UgiInstrumentation.java:51) at org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation.java:217) at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:185) at org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled(UserGroupInformation.java:237) at org.apache.hadoop.security.KerberosName.(KerberosName.java:79) at org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation.java:210) at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:185) at org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled(UserGroupInformation.java:237) at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:482) at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:468) at org.apache.hadoop.fs.FileSystem$Cache$Key.(FileSystem.java:1519) at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1420) at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:254) at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:123) at PutMerge.main(PutMerge.java:16) Caused by: java.lang.ClassNotFoundException: org.apache.commons.configuration.Configuration at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 17 more



根据一些帖子的输入,我添加了commons包。我的类路径定义是
/usr/java/jdk1.7.0_21:/data/commons-logging-1.1.2/commons-logging-1.1.2.jar:/data/hadoop-1.1.2/hadoop-core-1.1.2.jar:/data/commons-logging-1.1.2/commons-logging-adapters-1.1.2.jar:/data/commons-logging-1.1.2/commons-logging-api-1.1.2.jar:.

关于为什么这不起作用的任何线索?

最佳答案

您没有在类路径中包括apache configuration

确实,尽管您不需要在hadoop本身之外包含很多内容。确保您使用的是hadoop本身。
> hadoop -jar myJar.jar

关于hadoop - 获取ClassNotFound异常:在Hadoop中转储配置时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16550729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com