我是hadoop的新人。我正在使用猪0.14.0和hadoop 1.2.1。我已经在本地和地图缩减模式下成功地从grunt shell和pig batch脚本运行了pig。现在我正试图用Java中的嵌入式猪来运行猪。 当我在eclipse中编译我的代码时,我得到以下错误:
线程中的异常" main" java.lang.NoClassDefFoundError: org / apache / commons / logging / LogFactory at org.apache.pig.impl.util.PropertiesUtil。(PropertiesUtil.java:34) 在org.apache.pig.PigServer。(PigServer.java:202)at test.main(test.java:6)引起: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 at java.lang.ClassLoader.loadClass(ClassLoader.java:358)... 3更多
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();
}
}
}
请帮帮我。提前谢谢。
答案 0 :(得分:1)
请添加公共依赖:
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>