当我运行mapreduce的单元测试时,出现以下异常。我已经进口了所有可能的jar。我不知道我哪里出错了。我已经包括了下面我导入的jar的截图。
我在测试一个简单的代码:
import java.io.IOException;
import junit.framework.TestCase;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mrunit.mapreduce.*;
import org.junit.Test;
public class TestExample extends TestCase {
public static class maptest extends Mapper<LongWritable, Text, Text, IntWritable>{
Text day=new Text();
public void map(LongWritable key,Text value,Context ct)throws IOException,InterruptedException
{
String[] line=value.toString().split(",");
int val=Integer.parseInt(line[0]);
day.set(line[1]);
ct.write(day,new IntWritable(val));
}
}
MapDriver<LongWritable, Text, Text, IntWritable> mapDriver;
public void setUp() {
new maptest();
mapDriver = MapDriver.newMapDriver( new maptest());
}
@Test
public void testMapper() {
try {
mapDriver.withInput(new LongWritable(), new Text("1,sunday,abhay,holiday"))
.withOutput(new Text("sunday"), new IntWritable(1))
.runTest();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我有以下例外情况:
java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils
at org.apache.hadoop.fs.Path.normalizePath(Path.java:237)
at org.apache.hadoop.fs.Path.initialize(Path.java:203)
at org.apache.hadoop.fs.Path.<init>(Path.java:172)
at org.apache.hadoop.mrunit.MapDriverBase.<init>(MapDriverBase.java:45)
at org.apache.hadoop.mrunit.mapreduce.MapDriver.<init>(MapDriver.java:73)
at org.apache.hadoop.mrunit.mapreduce.MapDriver.<init>(MapDriver.java:69)
at org.apache.hadoop.mrunit.mapreduce.MapDriver.newMapDriver(MapDriver.java:221)
at TestExample.setUp(TestExample.java:35)
at junit.framework.TestCase.runBare(TestCase.java:139)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.StringUtils
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 22 more
导入的jar文件--单击此处
暂无答案!
目前还没有任何答案,快来回答吧!