Search code examples
eclipsemavenhadoopjaravro

Eclipse: confusing add to Build Path options


I'm not an "real" developper, but I have the right to at least write some code, and add some Jars to the Eclipse build path, without spending hours trying to figure out if the Jars are actually in the Build Path.

My problem (error here below) was resolved in question [NoClassDefFoundError, cannot run MapReduceColorCount (Avro 1.7.7) by adding the correct Jars.

    [cloudera@localhost ~]$ hadoop jar avroColorCount.jar exos.MapReduceColorCount2 inavro01 outavro01
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/avro/mapreduce/AvroKeyInputFormat
    at exos.MapReduceColorCount2.run(MapReduceColorCount2.java:71)
    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:84)
    at exos.MapReduceColorCount2.main(MapReduceColorCount2.java:86)
    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)

The following are the different ways I've tried to add Jars to the build path:

1. Maven: adding Dependencies through the POM file, they appear afterwards under "Maven Dependencies".

2. "Configure Build Path": the Jars are actually located in my local file system, thus I add the (library) folders, and the folders appear under the "Referenced Libraries".

3. Create a "lib" folder in the project folder, copy/paste the Jars (located in my local file system), do a project Refresh (the lib folder appears in the Package Explorer), select all Jars and right-click "Add to Build Path"

I confirm that my code show no warnings/errors while performing either method. I usually to an "Export ..." of the Jar file in order to execute it.

Example: I've tried adding to Build Path external Jars from Cloudera's CDH5 (Hadoop 2.3.0-cdh5.1.2 and Avro 1.7.5-cdh5.1.2) which are localted locally in /opt/lib

The only method that really worked was method 3. Why it doesn't work with methods 1. or 2. ?

Thank you in advance for your support


Solution

  • I could not reproduce success with method 3., I received a "cannot cast to namespace.customClass" error instead of the "NoClassDefFoundError" error.

    I've found an answer for the latter error with a workaround based on two variables export:

    export LIBJARS=avrojar1,avrojar2,jar3

    export HADOOP_CLASSPATH=avrojar1:avrojar2:jar3

    and then running the hadoop jar command with -libjars ${LIBJARS}. This was tested with method 1. and method 3. respectively.

    I conclusion, my case was specific to avro-related Jars only

    Thanks