NoClassDefFoundError: org/json/JSONObject - Hadoop MapReduce

2.3k views Asked by At

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?

2

There are 2 answers

0
Ramzy On BEST ANSWER

You can use jackson to process json.

<repositories>
    <repository>
        <id>codehaus</id>
        <url>http://repository.codehaus.org/org/codehaus</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.8.5</version>
    </dependency>
  </dependencies>

or google's gson

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>1.7.1</version>
</dependency>
1
Turbero On

Try:

<dependency>
    <groupId>net.sf.json-lib</groupId>
    <artifactId>json-lib</artifactId>
    <version>2.4</version>
</dependency>