user2153145
user2153145

Reputation: 3

how to clear NoClassDefFoundError

On running my java program for file copy to hdfs i am get following exceptions

hduser@master:~/Desktop/Source Code$ java -cp . Filesize monis.txt /home/hduser/Desktop/Source*/monis.txt /tmp/user/gutenberg



Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration
at FileSize.copyFromLocal(FileSize.java:219)
at FileSize.main(FileSize.java:74)
    Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 2 more

i have defined my CLASSPATH variable in /etc/environment file and it looks like such

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" 

CLASSPATH="/usr/local/hadoop/hadoop-core-1.0.4.jar:/usr/local/hadoop/lib/commons-cli-1.2.jar:/usr/local/hadoop/lib/commons-logging-1.1.1.jar:/usr/local/hadoop/lib/log4j-1.2.15.jar:/home/hduser/Desktop/Source*/"

Still I am getting this exception.

Upvotes: 0

Views: 1043

Answers (1)

Chris White
Chris White

Reputation: 30089

I'd be careful mixing the CLASSPATH environment variable and the -cp flag to java - which is most probably overriding the environment variable you've set in your /etc/environment.

You should also check that the changes you've made to /etc/environment have taken affect:

#> echo $CLASSPATH

If this doesn't show the values you've set then you most probably need to restart your shell session, log out and in again, or you could just source the file:

#> source /etc/environment

On a side note, the best way to run programs that interact with hadoop is via the hadoop shell script. You'll need to bundle up your classes into a jar file, but then it's easy to invoke your program, letting the script take care of adding the hadoop and other library dependencies to the classpath:

#> /usr/local/hadoop/bin/hadoop myJar.jar \
      Filesize monis.txt \
      /home/hduser/Desktop/Source*/monis.txt \
      /tmp/user/gutenberg

Upvotes: 1

Related Questions