0

I'm new in hadoop. I am using pig 0.14.0 and hadoop 1.2.1. I have successfully run pig from grunt shell and pig batch script in both local and map reduce mode. Now I am trying to run pig from embedded pig in Java. When I compile my code in eclipse I get following error :

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.pig.impl.util.PropertiesUtil.(PropertiesUtil.java:34) at org.apache.pig.PigServer.(PigServer.java:202) at test.main(test.java:6) Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory 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) ... 3 more

import org.apache.pig.ExecType;
import org.apache.pig.PigServer;
public class test {
    public static void main(String[] args) {
        try {
            PigServer pigServer = new PigServer(ExecType.MAPREDUCE);
            runQuery(pigServer);
        }catch(Exception e) {
            e.printStackTrace();
        }
    }
    public static void runQuery(PigServer pigServer) {
        try {
            pigServer.registerQuery("input1 = LOAD '/mydata/wct.txt' as (line:chararray);");
            pigServer.registerQuery("words = foreach input1 generate FLATTEN(TOKENIZE(line)) as word;");
            pigServer.registerQuery("word_groups = group words by word;");
            pigServer.registerQuery("word_count = foreach word_groups generate group, COUNT(words);");
            pigServer.registerQuery("ordered_word_count = order word_count by group desc;");
            pigServer.registerQuery("store ordered_word_count into '/mydata/wct';");
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}

Please help me. thanks in advance.

1 Answer 1

1

please add commons dependency:

<dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.1.1</version>
  </dependency>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.