Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JAR file contain a class, and is in CLASSPATH, but JVM cant find the class.

807580Jan 1 2010 — edited Jan 2 2010
Hello Friends:

I'm sure this has been answered, perhaps numerous times in the past... although I can't find a concrete
answer to this rather simple question myself (thusly replies truly appreciated). The issue:

When executing a Java class that relies on other classes contained in one-or-more JAR files; and said JAR
files do indeed contain the expected classes, and in the expected relative package directory structure;
sometimes the JVM cannot find a class within a JAR file (... not a bunch of them -- just, like, one perhaps).

Naturally, prior to the execution of "java MyMainClass", there's a scripted for-loop that enumerates the
JAR file directory (directories) needed to generate the CLASSPATH containing the colon separated
JAR file list (In other words, it's in the CLASSPATH).

To be more concrete, here's an example. The running JVM process shown below (ps -awwx) requires
(among other things) the class "*{color:#0000ff}org/mortbay/thread/ThreadPool{color}*" which, as shown, does exists in
the CLASSPATH via the containing JAR file "_*{color:#0000ff} /home/hadoop/bin/../lib/jetty-util-6.1.14.jar{color}*_"...

hadoop@hadoop1$ jar -tvf jetty-util-6.1.14.jar | grep -i ThreadPool
*[ ... partial grep(1) output elided ... ]*
328 Thu Nov 13 17:38:18 EST 2008 *{color:#0000ff}org/mortbay/thread/ThreadPool.class{color}* <-- there it is, and see CLASSPATH used in the JVM process below.
*[ ... partial grep(1) output elided ... ]*

hadoop@hadoop1$ ps -awwx
*[ ... partial ps(1) output elided ... ]*
5281 pts/0 Sl 0:01 /home/hadoop/APPS.d/SunJDK.d/latest/bin/java -Xmx768m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote -Dhadoop.log.dir=/home/hadoop/bin/../logs -Dhadoop.log.file=hadoop-hadoop1-namenode-hadoop1.log -Dhadoop.home.dir=/home/hadoop/bin/.. -Dhadoop.id.str=hadoop1 -Dhadoop.root.logger=INFO,DRFA -Djava.library.path=/home/hadoop/bin/../lib/native/Linux-amd64-64 -Dhadoop.policy.file=hadoop-policy.xml -classpath /home/hadoop/bin/../conf:/home/nmvega/APPS.d/SunJDK.d/latest/lib/tools.jar:/home/hadoop/bin/..:/home/hadoop/bin/../hadoop-0.20.1-core.jar:/home/hadoop/bin/../lib/commons-cli-1.2.jar:/home/hadoop/bin/../lib/commons-codec-1.3.jar:/home/hadoop/bin/../lib/commons-el-1.0.jar:/home/hadoop/bin/../lib/commons-httpclient-3.0.1.jar:/home/hadoop/bin/../lib/commons-logging-1.0.4.jar:/home/hadoop/bin/../lib/commons-logging-api-1.0.4.jar:/home/hadoop/bin/../lib/commons-net-1.4.1.jar:/home/hadoop/bin/../lib/core-3.1.1.jar:/home/hadoop/bin/../lib/hsqldb-1.8.0.10.jar:/home/hadoop/bin/../lib/jasper-compiler-5.5.12.jar:/home/hadoop/bin/../lib/jasper-runtime-5.5.12.jar:/home/hadoop/bin/../lib/jets3t-0.6.1.jar{color:#000000}:/home/hadoop/bin/../lib/jetty-6.1.14.jar{color}:_*{color:#0000ff}/home/hadoop/bin/../lib/jetty-util-6.1.14.jar{color}*_:/home/hadoop/bin/../lib/junit-3.8.1.jar:/home/hadoop/bin/../lib/kfs-0.2.2.jar:/home/hadoop/bin/../lib/log4j-1.2.15.jar:/home/hadoop/bin/../lib/oro-2.0.8.jar:/home/hadoop/bin/../lib/servlet-api-2.5-6.1.14.jar:/home/hadoop/bin/../lib/slf4j-api-1.4.3.jar:/home/hadoop/bin/../lib/slf4j-log4j12-1.4.3.jar:/home/hadoop/bin/../lib/xmlenc-0.52.jar:/home/hadoop/bin/../lib/jsp-2.1/jsp-2.1.jar:/home/hadoop/bin/../lib/jsp-2.1/jsp-api-2.1.jar:/home/nmvega/APPS.d/APACHE_HADOOP.d/latest/lib org.apache.hadoop.hdfs.server.namenode.NameNode
*[ ... partial ps(1) output elided ... ]*

The only reason the above JVM process ran at all is because, as a temporary work-around, I copied the "_*{color:#0000ff} /home/hadoop/bin/../lib/jetty-util-6.1.14.jar{color}*_" JAR file to
the "${JAVA_HOME}/jre/lib/ext/"directory. Were I to remove it from there, the following exception occurs:

2010-01-01 19:29:30,270 ERROR org.apache.hadoop.hdfs.server.namenode.NameNode: java.lang.NoClassDefFoundError: *{color:#0000ff}org/mortbay/thread/ThreadPool{color}*

Yet from the above, the JAR file exists in the CLASSPATH used, and the class exists in the JAR file (and in the expected package path location).

This happens every once in a while with other JAR files and CLASSES. Why would it find them in .../jre/lib/ext and not in the CLASSPATH.

Am I missing something? Anyway to debug this further? I'm not into creating symlinks in .../jre/lib/ext as word arounds whenever this problem pops
up, so I need to understand further. Your input is appreciated.

Thanks in advance,
Noel Milton
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 30 2010
Added on Jan 1 2010
3 comments
7,625 views