Tuesday, June 19, 2007

Configuring Ant in Linux

I solved this problem a couple of years ago, but now it popped up again and I had forgotten how to solve it and wasted some time. So for my own sake, and in case people are Googling for it:

If you get
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher
when running ant first of all run "which ant" and "which java" to see which programs are being executed. You might discover (like I did) that the server is running an old gcj and there is an old systemwide ant. Export ANT_HOME, JAVA_HOME to correct the dirs. Also
export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH

If you STILL get NoClassDefFoundError, you might find that there is a
/etc/ant.conf
file which trips you up, you might have to set ANT_HOME and JAVA_HOME properties there too! Or like Michael-N suggests, run ant --noconfig -version

The best solution though, tends to be to uninstall gcj, as well as all old system wide java tools that came with your distro. Instead of using RPM or similar, download the latest source directly from Sun. Things might improve now that Java is open source though.

No comments: