Search code examples
javahadoopcloudera-quickstart-vmhipi

HIPI test run fails due to NoclassdefinitionFound


I have been trying to follow the tutorial on a cloudera VM (cdh-5.4.2) but I am getting an exception when trying to run the built jar to count the number of pixels.

The build itself succeeds:

[cloudera@quickstart helloWorld]$ gradle jar
:core:compileJava UP-TO-DATE
:core:processResources UP-TO-DATE
:core:classes UP-TO-DATE
:core:jar UP-TO-DATE
:examples:helloWorld:compileJava UP-TO-DATE
:examples:helloWorld:processResources UP-TO-DATE
:examples:helloWorld:classes UP-TO-DATE
:examples:helloWorld:jar

BUILD SUCCESSFUL

Total time: 18.436 secs

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.7/userguide/gradle_daemon.html

But executing the jar throws the following error:

[cloudera@quickstart helloWorld]$ hadoop jar build/libs/helloWorld.jar examples/sampleNew.hib sampleimages_average
Exception in thread "main" java.lang.NoClassDefFoundError: org/hipi/imagebundle/mapreduce/HibInputFormat
    at org.hipi.examples.HelloWorld.run(HelloWorld.java:106)
    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:84)
    at org.hipi.examples.HelloWorld.main(HelloWorld.java:129)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.ClassNotFoundException: org.hipi.imagebundle.mapreduce.HibInputFormat
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 10 more

My build.gradle for this sub-project within example folder of same root hipi parent project is as below:

 jar {
  manifest {
    attributes("Main-Class": "org.hipi.examples.HelloWorld")

  }

  dependencies{
    compile project(':core')
  }
}

Can somebody help me what I am missing and how to make it run?

java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

Since I am new to gradle I didn't able to configure hipi under eclipse for using in other projects so I am trying to run through terminal only. Can anybody help me in that as well?

Note : I am having restricted internet access so having almost no download permission in my system.


Solution

  • I have resolved this problem by including all files in jar through gradle as below

    jar {
      manifest {
        attributes("Main-Class": "org.hipi.examples.HelloWorld")
      }
    
      dependencies{
        compile project(':core')
      }
    
     from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
    }