Problems installing ANT: Exception in thread “main” java.lang.NoClassDefFoundError 2

Posted by nick.stielau on October 01, 2007

I ran into some trouble installing ANT for use with the Flex2 SDK. I kept getting the following error:

CODE:
  1. [nick@dolores PIMP]$ ant
  2. Buildfile: build.xml
  3.  
  4. default:
  5.  
  6. release:
  7.      [echo] compiling the release version of pimp.swf
  8.      [exec] Warning: -Xmx384m not understood. Ignoring.
  9.      [exec] Warning: -jar not understood. Ignoring.
  10.      [exec] Exception in thread "main" java.lang.NoClassDefFoundError: .opt.flex2_sdk.bin....lib.mxmlc.jar
  11.      [exec]    at gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.5.0.0)
  12.      [exec]    at _Jv_ThreadRun(java.lang.Thread) (/usr/lib/libgcj.so.5.0.0)
  13.      [exec]    at _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/lib/libgcj.so.5.0.0)
  14.      [exec]    at __gcj_personality_v0 (/home/nick/PIMP/src/main/actionscript/java.version=1.4.2)
  15.      [exec]    at __libc_start_main (/lib/tls/libc-2.3.4.so)
  16.      [exec]    at _Jv_RegisterClasses (/home/nick/PIMP/src/main/actionscript/java.version=1.4.2)

Everything I could find on google or apache.org pretty much just said "Check your JAVA_HOME and ANT_HOME varables". In the end they were right (kinda), but it was not very helpful at the time.

CODE:
  1. [nick@dolores PIMP]$ echo $JAVA_HOME && echo $ANT_HOME
  2. /usr/java/jdk1.5.0_08
  3. /opt/ant

Eventually I noticed the "java.version=1.4.2" line, which is a little odd, since I thought java 1.5 would be on the box.

CODE:
  1. [nick@dolores PIMP]$ /usr/bin/java -version
  2. java version "1.4.2"
  3. gcj (GCC) 3.4.6 20060404 (Red Hat 3.4.6-3)
  4. Copyright (C) 2006 Free Software Foundation, Inc.
  5. This is free software; see the source for copying conditions.  There is NO
  6. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

That's odd, why is 1.4.2 coming up? Lets check what Java stuff is here

CODE:
  1. [nick@dolores PIMP]$ sudo find / -name java
  2. Password:
  3. /usr/share/doc/db4-devel-4.2.52/ref/java
  4. /usr/share/doc/libidn-devel-0.5.6/contrib/java
  5. /usr/share/java
  6. /usr/share/javadoc/java
  7. /usr/java
  8. /usr/java/jdk1.5.0_08/jre/bin/java
  9. /usr/java/jdk1.5.0_08/bin/java
  10. /usr/bin/java

So there are at least two executables, whats the deal?

CODE:
  1. [nick@dolores PIMP]$ ls -l /usr/bin/java*
  2. lrwxrwxrwx  1 root root 22 Mar 13  2007 /usr/bin/java -> /etc/alternatives/java

Hmm. A symlink. Well, I don't really know what is going on with this box, so instead of messing around, I'll just set my path to look for Java 1.5 first.

[code]

export PATH=/usr/java/jdk1.5.0_08/bin:$PATH

[\code]

And it works! Hurray. Hope that helps. It's probably a good idea to look for existing Java and Ant files right up front, that way some crap like /etc/alternatives won't bite you in the butt for 2 hours.