I'm attempting to run a MapReduce job from a jar file and keep getting a ClassNotFoundException error. I'm running Hadoop 1.2.1 on a Centos 6 virtual machine.
First I compiled the file exercise.java (and class) into a jar file exercise.jar using the following shell script compile.sh :
#!/bin/bash
javac -classpath /pathto/hadoop-common-1.2.1.jar:\
/pathto/hadoop-core-1.2.1.jar /pathto/exercise.java
jar cvf exercise.jar /pathto/*.class
This runs fine and the jar completes successfully. I then attempt to run the actual MapReduce job using shell script exec.sh:
#!/bin/bash
export CLASSPATH=$CLASSPATH:/pathto/hadoop-common-1.2.1.jar:\
/pathto/hadoop-core-1.2.1.jar:/pathto/exercise.class
hadoop jar exercise.jar exercise /data/input/inputfile.txt /data/output
This trows the ClassNotFoundException error :
Exception in thread "main" java.lang.ClassNotFoundException: exercise
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.apache.hadoop.util.RunJar.main(RunJar.java:153)
I realize the explicit path names might not be necessary but I've been a little desperate to double check everything. I've confirmed that in my exercise.java file exercise.class is in the job configuration via job.setJarByClass(exercise.class); and confirmed exercise.class is contained in exercise.jar. Can't seem to figure it out.
UPDATE
The exec.sh script with the full path of exercise.class. It's stored in my Eclipse project directory:
#!/bin/bash
export CLASSPATH=$CLASSPATH:/pathto/hadoop-common-1.2.1.jar:\
/pathto/hadoop-core-1.2.1.jar:/home/username/workspace/MVN_Hadoop/src/main/java.com.amend.hadoop.MapReduce/*
hadoop jar \
exercise.jar \
/home/username/workspace/MVN_Hadoop/src/main/java.com.amend.hadoop.MapReduce/exercise \
/data/input/inputfile.txt \
/data/output
When I actually try and run the exec.sh script using the explicitly written out path names, I also get a completely different set of errors:
Exception in thread "main" java.lang.ClassNotFoundException: /home/hdadmin/workspace/MVN_Hadoop/src/main/java/come/amend/hadoop/MapReduce/exercise
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.apache.hadoop.util.RunJar.main(RunJar.java:153)
I could see this possible errors.
From the Hadoop jar exercise.jar exercise /data/input/inputfile.txt /data/output please specify the full path of the exercise class. I.e org.name.package.exercise if exists. To cross check open the jar file and check the location of exercise.class location.
To continue, Hadoop doesn't expect jars to be included within the jars, since the path of Hadoop is set globally.
NEW:
See, the following path is some thing weird. "/home/hdadmin/workspace/MVN_Hadoop/src/main/java/come/amend/hadoop/MapReduce/exercise"
If you are running using your jar, how could a class path be so specific, instead of jar path. It could only be "come/amend/hadoop/MapReduce/exercise" this.
Related
I found the following project on github https://github.com/fbukevin/hadoop-cooccurrence which uses a co-occurrence algorithm in hadoop.
I’m using a virtualized Ubuntu 14.04 and managed to install hadoop as a single node cluster with this instruction http://www.bogotobogo.com/Hadoop/BigData_hadoop_Install_on_ubuntu_single_node_cluster.php. I'm new to hadoop and this are my first attempts to run a program with yarn.
I can execute the command yarn in command line, but I don’t know how to run the co-occurrence algorithm in yarn. In the description it says that the program can be used with the following command
$ yarn jar <hadoop>.jar [pairs | stripes] <input_file>
So I tried this:
$ yarn jar /home/vmiller/Downloads/hadoop-2.7.2/share/hadoop/common/hadoop-common-2.7.2.jar pairs pg100.txt
Exception in thread "main" java.lang.ClassNotFoundException: pairs
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:278)
at org.apache.hadoop.util.RunJar.run(RunJar.java:214)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
This is definitely not correct but I don't know how to run the command correctly. Somehow I have to tell yarn to use the Cooccurrence.java located in hadoop-cooccurrence/src/main/java/cooc/Cooccurrence.java because this file seems to be the one that executes the co-occurrence algorithm. But how do I tell yarn to use this file with the pairs and stripesarguments on the input file?
You should give jar the path to the jar including the Cooccurrence class.
Jar is in target folder (cooc-1.0-SNAPSHOT.jar).
You don't need to indicate the class name as it is set up in the Manifest file
I actually managed to run the programm. My approach wasn't that wrong, as tokiloutok mentioned I had to include the right jar file.
Before I could execute the command I had to import the pg100.txt into HDFS.
So I had to deactivate the safe mode of the name node with
hdfs dfsadmin -safemode leave
and import the file with
hdfs dfs -put /home/vmiller/workspace/hadoop-cooccurrence/pg100.txt /user/hadoop/
so that I could finally run
yarn jar target/cooc-1.0-SNAPSHOT.jar pairs pg100.txt
without getting any errors.
Successfully compiled my Hbase class using
javac -cp "/hbase/lib/*" CreateTable.java
But during running it is throwing error
java CreateTable
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration
at CreateTable.main(CreateTable.java:16)
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 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 1 more
javac -cp `hbase classpath` CreateTable.java
java -cp `hbase classpath` CreateTable
where hbase classpath is cluster classpath where cluster has installed hbase jar files
If you want to see folder location of your hbase/lib,
you can go to hbase shell and try your hbase lib jars will be displayed there.
Note : if you are using maven for your build then you have to set 'provided' as scope where you are mentioning groupid, artifactid etc...
In addition to specifying the classpath of libraries you're depending on in order to compile your program, you need to specify them when executing your program. The dependencies aren't "compiled-in", they're just referenced during compilation to ensure that they're linked correctly, but they need to be there at runtime as well.
So, you probably want to run something like java -cp ".;/hbase/lib/*" CreateTable in order to have the same libraries at runtime as you used at compile time, as well as the current directory where your complied .class file is.
In enterprise programs, usually a dependency management system like Maven, or at least what's built into most IDEs, is used to help keep track of the dependencies and call Java and related tools with the right paths.
I am running my hadoop job and it is failing on class not found. 4 java files in total.
logProcessor.java
logMapper.java
logReducer.java
logParser.java
Everything is in a com folder on unix and I have "package com;" in the first line in all classes
that means if you do below command
head -5 *java
You will see
package com;
in all 4 files.
logProcessor is the Driver class. All files are in "com" folder on unix.
ls -ltr com/
logProcessor.java
logMapper.java
logReducer.java
logParser.java
I compiled the java program and made a jar out of it.
hadoop jar /var/lib/hadoop-hdfs/xxxx/jarFiles/LogParser.jar com.LogProcessor /user/hdfs/flume/2015-03-30/03 /user/xxxx/output_xxx
It gives me below error:
Exception in thread "main" java.lang.ClassNotFoundException: com.RFCLogProcessor
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at org.apache.hadoop.util.RunJar.main(RunJar.java:201)
First, you need to write your jar path in classpath. write directory path of your jar file into .bashrc file.
Then you can using below command:
hadoop jar directorypath/yourjarname.jar packagename.mainclassname outputpath
Everything that I was doing was right. Except that the classes which got created didnt have execute permission on them
So I did
chmod -R 777 com/
and jar'd it again and ran it with same above command and it executed.
I'm writing a java app and running it on a linux ec2 server.
the program was running fluently yesterday, and after I changed and organazied some files and packages I'm getting this problem when I execute the program:
I'm running the programm with this command:
java -cp . main.Server
And get the following error:
Exception in thread "Thread-0" java.lang.NoClassDefFoundError: org/json/JSONObject
at main.Group.<init>(Group.java:28)
at main.Server.run(Server.java:23)
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject
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)
... 2 more
I was running the programm as this before the changes:
export CLASSPATH=$CLASSPATH:/home/ec2-user/java-json.jar
In the bin folder, command:
java Server
And the programm was running.
Since I changed the package from default name to main, I need to run it with the command java -cp . main.Server, but I get the error written above.
I also tried modifing the .bash_profile and add this:
CLASSPATH=$CLASSPATH:/home/ec2-user/java-json.jar
export CLASSPATH
But it didn't help.
I have no errors in my code and the jar is not broken since it worked before. What should I do to fix this problem?
Specify the jar file on the classpath like this:
java -cp .:/home/ec2-user/java-json.jar main.Server
If your classpath is indeed correctly set in your .bash_profile, you could also do:
java -cp .:$CLASSPATH main.Server
I made a java class using the library Jaudiotagger, and it runs without problems. I then made a jar out of it and I got NoClassDefFoundError. Here's how it went:
I put the main class id3tag.java and the library jaudiotagger-2.0.3.jar in a folder and compiled using the command line. The program ran smoothly without problems.
javac -cp .;jaudiotagger-2.0.3.jar id3tag.java
java -cp .;jaudiotagger-2.0.3.jar id3tag
I then created the manifest and the jar file.
echo Main-Class: id3tag >manifest.txt
jar cvfm id3tag.jar manifest.txt id3tag.class jaudiotagger-2.0.3.jar
I got the following output:
added manifest
adding: id3tag.class(in = 5952) (out= 2997)(deflated 49%)
adding: jaudiotagger-2.0.3.jar(in = 811441) (out= 740599)(deflated 8%)
I then ran the jar file, and got "A Java Exception has occurred.". I also tried:
java -jar id3tag.jar
And I got the output:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaudiotagger/tag/
FieldDataInvalidException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
at java.lang.Class.getMethod0(Class.java:2694)
at java.lang.Class.getMethod(Class.java:1622)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.jaudiotagger.tag.FieldDataInval
idException
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)
... 6 more
I then replaced all (both) error classes used from Jaudiotagger with Exception and recreated the jar. Now the same thing happens as for seemingly all other jar files when I run them (with Java(TM) Platform SE binary, or through writing id3tag.jar in the command prompt) - nothing. java -jar, however, works and gave me a runtime error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaudiotagger/audi
o/AudioFileIO
at id3tag.tagSong(id3tag.java:112)
at id3tag.tagAlbum(id3tag.java:82)
at id3tag.tagArtist(id3tag.java:40)
at id3tag.main(id3tag.java:170)
Caused by: java.lang.ClassNotFoundException: org.jaudiotagger.audio.AudioFileIO
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)
... 4 more
It seems like the entire library just doesn't do shit for me. How do I fix this, and how do I get jar files to run without java -jar? (Also, how do I get the full pile'o'errors in case someone needs it, rather than just having it say "x more"?)
I'm not very savvy with this kinda shit so the more specific the answer, the better. Thanks.
I'm on windows 8 and latest java (1.7.0_17).
this is informing you that you have no main class, as you might or might not already know all programs in almost all non web based programming languages must have a main class to start from. In java it looks like this
public static int main(String[] args){
}
The message is informing you that this class is no longer there, this could be a compiler error or something entirely different.
please try downloading the library again, and downloading eclipse ide for java ee developers.
this ide has a built in compiler that will work better than a command line sometimes.
i hope this helped.
I worked around it by including the org folder from jaudiotagger in my .jar instead of the actual .jar file, and I then used a .bat file to run it instead of running the .jar directly. Feel free to add your own answer if you find a better solution, and I'll check back.
I extracted jaudiotagger-2.0.3.jar with winrar so that the org folder was in the same folder as my main class. Then I could compile and run the main class simply by:
javac id3tag.java
java id3tag
I then created the manifest file the same way as before, and created the jar:
jar cvfm id3tag.jar manifest.txt id3tag.class org
The jar file worked with java -jar id3tag.jar, but simply writing id3tag.jar still did nothing. Turns out it's because jar files are by default run by the javaw.exe file, so you have to right click the jar file -> open with -> choose default program and navigate to the java.exe file in your java folder (just search the folder). Running the .jar then gets you "Error: Could not find or load main class path\id3tag.jar". I worked around this by using a .bat file. I entered
java -jar path\id3tag.jar
into Notepad and saved as whatevername.bat (save as type: all files).
I created a new question for getting the .jar file to work properly. See .jar error - could not find or load main class.