1
votes

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

2

2 Answers

2
votes
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 enter image description here 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...

0
votes

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.