在cassandra中运行hadoop wordcount示例的例外情况

时间:2014-07-17 11:24:11

标签: hadoop cassandra cql3 word-count datastax

我有2个节点的集群,我正确地在这些节点上安装了hadoop和cassandra,当我在[https://github.com/apache/cassandra/tree/trunk/examples/hadoop_cql3_word_count]

中运行单词计数示例时

(首先运行wordcountsetup然后从wordcount创建jar并在hadoop中运行它)我得到异常:

Exception in thread "main" java.lang.NoClassDefFoundError: **com/datastax/driver/core/policies/LoadBalancingPolicy**
    at WordCount.run(WordCount.java:236)
    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
    at WordCount.main(WordCount.java:78)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
Caused by: java.lang.ClassNotFoundException: com.datastax.driver.core.policies.LoadBalancingPolicy
    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)
    ... 8 more

1 个答案:

答案 0 :(得分:0)

Mapreduce程序主要有两个部分。驱动程序部分,Map / Reduce部分。驱动程序部分将在触发mapreduce程序的同一台机器上执行,而Map / Reduce部分将在任何从属节点中执行。在这里,您将面临 NoClassDefFoundError ,这意味着您的驱动程序代码或Mapper / Reduce代码中无法访问类 com.datastax.driver.core.policies.LoadBalancingPolicy

如果驱动程序代码有异常,则在执行hadoop命令之前设置环境变量。需要找到包含类 com.datastax.driver.core.policies.LoadBalancingPolicy 的Jar,在占位符中指定jar完整路径

export HADOOP_CLASSPATH=<_JAR_NAME>;     # 

如果异常来自Mapper / Reducer,则上述选项不起作用。在这种情况下,通过在jar(myJar.jar)中添加依赖的jar来创建一个胖罐

或者使用hadoop -libjars选项(需要在Main类中覆盖ToolRunner类)