views:

69

answers:

2

Hello,
I'm having problem with using external jars in my file. I always get
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration
at this line: Configuration config = HBaseConfiguration.create();
And this file is on the classpath, I'm setting options when running jar:
java -jar hbase.jar -classpath "/usr/lib/hbase/*:/usr/lib/hadoop/*"

This file compiles successfully after invoking this command: javac -classpath "/usr/lib/hbase/*:/usr/lib/hadoop/*" HBaseScanner.java

What to do?

+1  A: 

JVM will throw java.lang.NoClassDefFoundError if the class loader cannot initialize static members of a class, say an exception is thrown. Or if it cannot find another class that is accessed by a static initializer in this class. This looks like what is happening, when class loader tires to load HBaseConfiguraton, this class HBaseConfiguration is expecting something that it cannon get that leads to an exception, that is lost.
Tough luck debugging this sort of failures.

EDIT: The easiest way to figure out what is missing is to launch the program in a debugger with all HBase sources connected, say under Eclipse, and trace the HBaseConfiguration.create() call.

hidralisk
A: 

My problem was that I was setting classpatch using -classpath option and running jar, what causes -classpath option to be ignored.

I have added jars in manifest file and this works.

This is similar problem: http://stackoverflow.com/questions/219585/setting-multiple-jars-in-java-classpath

Wojtek