java.lang.NoClassDefFoundError in Hadoop-1.0.1 - java

i am working with Hadoop-1.0.1 in Eclipse. I am trying to run wordcount application but when i run my WordCount.java, Eclipse shows me following error
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.hadoop.conf.Configuration.<clinit>(Configuration.java:143)
at test.WordCount.main(WordCount.java:56)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 2 more
I have hadoop-core-1.0.1.jar in my classpath. Should the application require more jar

It seems you are getting this error because either two important logging classes commons-logging-1.1.1.jar and commons-logging-api-1.0.4.jar which are related with common logging is either not available from your classpath or you just don't have it.
In most cases these files are in \lib folder with other Hadoop Jar so when you set class path these jar are accessible. Please verify that you do have these files in your machine and are set in your classpath so they are accessible.
Also when you run "hadoop version" the version comes up as result, the same hadoop-core--SNAPSHOT.jar must be in your $HADOOP_HOME location.
You mentioned that you are running WordCount.java instead you should say that you are running WordCount job because you are always using the compiled application as jar not java.
$ bin/hadoop jar /usr/jboss/wordcount.jar org.myhadoop.WordCount /usr/jboss/wordcount/input /usr/jboss/wordcount/output

hadoop-core-1.0.1 is probably not in your classpath: commons-logging is actually included several times in the hadoop jar!

It seems that you did not include the common-logging jar file so Download Here the jar file depends on version, Then will included it in your program and run it THANK yoU

Related

Unable load jar from my jar: NoClassDefFoundError

I have this jar:
/weekly/
/database.class
/report.class
/META-INF
/MANIFEST.MF
The MANIFEST.MF
Manifest-Version: 1.0
Main-Class: weekly.report
Class-Path: /root/java
In this jar i used two external jar files, postgresql-9.1-901.jdbc4.jar, javax.mail.jar. I also put those into /root/java.
but when i run it use
java -jar weekly.jar
It shows those two jars class can't find
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/internet/AddressException
Caused by: java.lang.ClassNotFoundException: javax.mail.internet.AddressException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
even i try to put those two jars to my $CLASSPATH
/usr/java/jdk1.6.0_21/lib:/usr/java/jdk1.6.0_21/jre/lib
It also shows same error result. I can successfully run it in my Mac, but when i try to remove it to my server CentOS system ,it shows those NoclassDefFounderror.
Finding a JAR file using a classpath is similar to finding a package
file in a classpath. The difference is that when you specify a path
for a JAR file, you must include the name of the JAR file at the end
of the path.
So you can try something like this:
java -classpath /usr/java/jdk1.6.0_21/lib/javax.mail.jar:/usr/java/jdk1.6.0_21/jre/lib/postgresql-9.1-901.jdbc4.jar -jar weekly.jar
Another option is to put your jars into jre/lib/ext (but I don't think it's a good idea)

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.

Are there any detailed instructions for how to use css-validator.jar? [duplicate]

I am trying to implement css-validator from w3 and it has failed with every attempt, raising an error message.
Here is the error I am getting:
"Directory Redacted"\framework-web>java -jar "Directory Redacted"\Downloads\
css-validator.jar http://www.w3.org
Exception in thread "main" java.lang.NoClassDefFoundError: org/w3c/tools/resourc
es/ProtocolException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
at java.lang.Class.getMethod0(Class.java:2774)
at java.lang.Class.getMethod(Class.java:1663)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.w3c.tools.resources.ProtocolExc
eption
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)
... 6 more
What exactly does this error message indicate and how do I fix it?
It would appear the application is using the class 'ProtocolException':
http://jigsaw.w3.org/Doc/Programmer/api/org/w3c/tools/resources/ProtocolException.html
It's likely that it is missing from your classpath. I would see if you can add the containing jar to your ant classpath.
Also if you take a look at Sinan's answer here:
How can I validate CSS on internal web pages?
Was there an ant build file which came with the application? If so, it might be as simple as running ant against that build.xml to get your dependencies, then run java -jar through command line.
I was very grateful when cluemein included the actual filenames but without the original versions and which ones were renamed, I still couldn't get css-validator to run. So I downloaded the most recent css-validator.jar and the most recent build.xml file from http://dev.w3.org/cvsweb/2002/css-validator/build.xml?rev=1.24;content-type=text%2Fplain.
I put the build.xml file and the jar in a directory and ran
ant prepare
Ant downloaded the expected jar versions for me and renamed them into the lib file. Then when I ran
java -jar css-validator.jar http://awesomesite.com
it worked fine.
Ok, it turns out I was missing 8 prerequisite .jar files that are needed for this to work. I put them in a folder titled lib in the same folder as css-validator.jar and it works perfectly afterward. The files are:
commons-collections-3.2.1.jar
commons-lang-2.6.jar
htmlparser-1.3.1.jar
jigsaw.jar
tagsoup-1.2.jar
velocity-1.7.jar
xercesImpl.jar
xml-apis.jar
Was a lot more than I expected that I was missing.
The documentation for css-validator.jar did not have the complete list, had to dance around the internet and even rename some jar files to make it work (removed version number for some of these.) If anyone else wants to use css-validator.jar, you will need these files

Creating jar file with manifest and audio and image folders including external jars

I am trying to create a jar file
having following project contents
Project
user_interface (package folder including all .classes related to GUI)
function_operations (package folder including all .classes related to operations)
sounds (folder include all sound files)
icons (include all images and icons)
jars (include all external jar files)
manifest.txt (having one line *Main-Class: user_interface.messengerGUI* and two enters)
i m using command
jar cvfm helloBuddy.jar manifest.txt user_interface/*.class function_operations/*.class icons/ sounds/
It successfully create jar file but gives following error while executing
JAI-MATA-DI-LINUX Project # java -jar helloBuddy.jar Exception in
thread "main" java.lang.NoClassDefFoundError:
user_interface/messengerGUI Caused by:
java.lang.ClassNotFoundException: user_interface.messengerGUI at
java.net.URLClassLoader$1.run(URLClassLoader.java:217) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:205) at
java.lang.ClassLoader.loadClass(ClassLoader.java:321) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at
java.lang.ClassLoader.loadClass(ClassLoader.java:266) Could not find
the main class: user_interface.messengerGUI. Program will exit.
another problem is how to include external jars?
Edited: finaly some success to jar formation. Using eclipse i am able to create jar file. But when i run it gives the following error
Exception in thread "main" java.lang.NoClassDefFoundError:
org/jivesoftware/smack/ChatManagerListener Caused by:
java.lang.ClassNotFoundException:
org.jivesoftware.smack.ChatManagerListener at
java.net.URLClassLoader$1.run(URLClassLoader.java:217) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:205) at
java.lang.ClassLoader.loadClass(ClassLoader.java:321) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at
java.lang.ClassLoader.loadClass(ClassLoader.java:266) Could not find
the main class: user_interface.messengerGUI. Program will exit.
I have included few external jar files in project.
org/jivesoftware/smack/ChatManagerListener this class belongs to one of the smackx.jar file.
so this error is of external jar files added to project. any clue how can i resolve this?
Try this, this is the way to create a jar or runnable jar in eclipse, all your external libraries in the project will be included
File -> Export-> Java ->Runnbale JAR file
Launch configuration : your Class containing the public static void main(String[] args)
Export destination : Target place
Library Handling:
Package required libraries into generated JAR
FINISH
You cannot nest jar files like that unless you use a custom class loader like jarclassloader or use a tool like onejar.

Why edit to Manifest file provides solution that CLASSPATH does not

I'm writing a short utility that performs a short task on a remote Oracle instance. The utility uses the Oracle jdbc driver found in ojdbc6.jar.
The Oracle jar is properly included in my classpath. When I export my project to a jar and run the jar on the command line using "java -jar ", I get:
Exception in thread "main" java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
After moving the Oracle jar into the same directory as my runnable jar file, I changed my Manifest file to include the the Oracle jar in the classpath. This fixed the problem, and my jar ran fine.
Can anyone explain why including the Oracle jar in my classpath didn't solve the problem, and why editing the Manifest file did?
Thanks!
From Sun (Oracle) documentation for the java -jar command:
Execute a program encapsulated in a JAR file. The first argument is
the name of a JAR file instead of a startup class name. In order for
this option to work, the manifest of the JAR file must contain a line
of the form Main-Class: classname. Here, classname identifies the
class having the public static void main(String[] args) method that
serves as your application's starting point. See the Jar tool
reference page and the Jar trail of the Java Tutorial for information
about working with Jar files and Jar-file manifests. When you use this
option, the JAR file is the source of all user classes, and other user
class path settings are ignored.

Categories