I'm trying to do a Mapreduce job using a Json as input. I imported JSON dependency in POM.xml and Maven clean install run properly. But when I run the Jar in Hadoop i get "NoClassDefFoundError: org/json/JSONObject" error on Mapper class. (I also tried with JSON Java external Jar, but it doesn't work.
This is my test mapper class:
package com.andrew.hadoopNBA.NbaJob1;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.json.*;
public class PointsRankingMapper extends Mapper<Object, Text, Text, IntWritable> {
public void map(Object key, Text value, Context context)
throws IOException, InterruptedException {
try {
JSONObject jsn = new JSONObject(value.toString());
System.out.println("printing JSON " + jsn);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
And this is Maven dependency:
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
Any ideas?
You can use jackson to process json.
or google's gson