Getting NoClassDefFoundError when trying to run a maintenance task on a servlet
I have a servlet app that is running fine, and not wanting to copy some of the classes to a separate project, developped a command-line maintenance tool within it. However on trying to run this tool, I am getting a NoClassDefFoundError:
[juhani@hadoop01 WEB-INF]$ java -classpath .:/usr/share/tomcat5/webapps/xyz/WEB-INF/classes/ xyz.logger.FileToHBaseTransfer
Exception in thread "main" java.lang.NoClassDefFoundError: xyz/logger/FileToHBaseTransfer
Caused by: java.lang.ClassNotFoundException: xyz.logger.FileToHBaseTransfer
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: xyz.logger.FileToHBaseTransfer. Program will exit.
Some sanity checks:
[juhani@hadoop01 WEB-INF]$ ls -al classes/xyz/logger/FileToHbaseTransfer.class
-rw-r--r-- 1 tomcat tomcat 2815 8月 10 16:02 classes/xyz/logger/FileToHbaseTransfer.class
[juhani@hadoop01 WEB-INF]$ javap -classpath ./classes/xyz/logger/ FileToHbaseTransfer
Compiled from "FileToHbaseTransfer.java"
public class xyz.logger.FileToHbaseTransfer extends java.lang.Object{
public xyz.logger.FileToHbaseTransfer();
public static void main(java.lang.String[]);
}
I've rechecked the docs for locating files at http://download.oracle.com/javase/6/docs/technotes/tools/findingclasses.html and I can't see anything obvious wrong though I'm sure it's something along those lines. Been stumped on this for a while and seem to have stopped making progress, so any help would be appreciated with finding the cause.
imports
(and the full unappended classpath which I am using. I was just eliminating it down to the 开发者_运维百科smallest relevant to avoid mixing in other problems): Any other dependencies are in the same package
package xyz.logger;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTablePool;
java -classpath .:/usr/share/tomcat5/webapps/xyz/WEB-INF/classes/:/usr/lib/hbase/:/usr/lib/hadoop/:/etc/hbase/conf/:/etc/hadoop/conf/ xyz.logger.FileToHBaseTransfer
Possibly relevant?
If I try to run javap with the proper claasspath it can't find the class:
[juhani@hadoop01 WEB-INF]$ javap -classpath ./classes/ xyz.logger.FileToHBaseTransfer
ERROR:Could not find xyz.logger.FileToHBaseTransfer
Just verifying the class format, it is indeed 1.6(http://en.wikipedia.org/wiki/Class_(file_format)):
[juhani@hadoop01 ~]$ hexdump /usr/share/tomcat5/webapps/xyz/WEB-INF/classes/xyz/logger/FileToHbaseTransfer.class
0000000 feca beba 0000 3200 8700 0007 0102 2600
Ok this is really stupid but after running in the eclipse debugger and painstakingly comparing the huge classpath, it turned out that what was wrong the whole time was me writing the classname as HBase rather than Hbase
Hope that serves as a warning to others, and that the random diagnostics I was doing might help someone else solve a related issue
精彩评论