开发者

External jars & HBase in classpath

开发者 https://www.devze.com 2023-01-11 18:04 出处:网络
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/HBaseConfigu开发者_如何学编程ration`

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/HBaseConfigu开发者_如何学编程ration`  
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?


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.


It would be really handy if java gave us an error or at least a warning in this situation. I believe one solution is to execute your jar like this

java -cp "myclasspath":myjarfile.jar MyClassname


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

I have added jars in manifest file and this works.

This is similar problem: Setting multiple jars in java classpath

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号