简体   繁体   中英

Hadoop MapReduce program runs fine in Eclipse but not when exported to .jar file

In Eclipse I add external libraries from three directories. The lib directory from hadoop, the same from hbase and two local directories from my Eclipse project with other jars. When executing the exported jar file I get out a ClassNotFoundException related with hbase. I'm sure that is a problem with my external libraries.

I execute the program just like that:

hadoop jar /home/brunneis/Escritorio/mr.jar Principal -libjars /bigdata/hbase/lib/*.jar,/home/brunneis/workspace/MapReduce/lib/*.jar,/home/brunneis/workspaces/MapReduce/lib1.1.2/*.jar

At the hadoop-env.sh file I also added this line:

export HADOOP_CLASSPATH="/bigdata/hbase/lib/*.jar;/home/brunneis/workspace/MapReduce/lib/*.jar;/home/brunneis/workspace/MapReduce/lib1.1.2/*.jar"

And this is what I get:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration
at Principal.main(Principal.java:27)
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:160)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration
    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 java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 6 more

Thank you so much.

NoClassDefFoundError comes when a class is not visible at run time but was at compile time. Which may be related to JAR files, because all the required class files were not included. And regarding your case below post might help you.

HBase - java.lang.NoClassDefFoundError in java

Pasting the answer from the above link.

It's Hbase client Java Program, you should not run it with "hadoop". It's should be a standard jar program running style, like: java -jar yourjar.jar

When you use ">jar -cvf TestHBase.jar -C TestHBase/ .", it doesn't garantee the jar dependencies can be found during runtime, which you face it.

In eclipse, the jar export function has a choice of "Runable" jar.

So suggest you run your testing class seprately with explicitly point out the dependent jar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM