title: Ant failure: Exception in thread “main” java.lang.NoClassDefFoundError org/apache/tools/ant/launch/Launcher
body: <p>I'm on Fedora 17. I am trying to compile a project with an ant build file which is not compatible with Java 7. So I decided to install OpenJDK 6. JDK 6 is unfortunately removed from yum repositories, and I figured it would be easy to install it manually. I learned that there is no JAVA_HOME variable and alternatives system is used instead. So I downloaded OpenJDK binaries (from OSG if it matters) and installed java &amp; javac &amp; javaws using <code>alternatives --install</code> command. Checking <code>java --version</code> and <code>javac --version</code> proved it to be successful. But the strange thing happened is that ant is not working any more! When I type <code>ant --execdebug</code> I receive this message: </p>
  
  <pre><code>exec "/usr/lib/jvm/openjdk-6.0.24/bin/java" -classpath "/usr/bin/build-classpath: 
  error: JVM_LIBDIR /usr/lib/jvm-exports/openjdk-6.0.24 does not exist or is not a 
  directory:/usr/bin/build-classpath: error: JVM_LIBDIR /usr/lib/jvm-exports/openjdk-6.0.24 
  does not exist or is not a directory:/usr/lib/jvm/openjdk-6.0.24/lib/tools.jar"
  -Dant.home="/usr/share/ant" -Dant.library.dir="/usr/share/ant/lib" 
  org.apache.tools.ant.launch.Launcher -cp ""
  Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher
  Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.Launcher
      at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
  Could not find the main class: org.apache.tools.ant.launch.Launcher. Program will exit.
  </code></pre>
  
  <p>As the case with java, there is no ANT_HOME variable too. But there wasn't an ANT_HOME even before installing java 6 while it was working fine. Ant is installed under /usr/bin/ant that's already in PATH.</p>
  
  <p><strong>UPDATE:</strong> I know there are similar questions <a href="https://stackoverflow.com/questions/2336299/what-is-wrong-with-my-ant-configuration">qustion 1</a>, <a href="https://stackoverflow.com/questions/2336299/what-is-wrong-with-my-ant-configuration">question 2</a>. But neither resolved my problem. For example adding ANT_HOME=/usr/bin deteriorates the situation, in that ant is not working even with JDK 7! Due to my unfamiliarity with alternatives system, I totally removed java related alternatives, added JAVA_HOME, and modified PATH instead. Again, java &amp; javac are working fine, with java --version returning the right version, but ant is returning the same error. As the <code>--execdebug</code> tells us, JVM_LIBDIR is not pointing to the right location. I suppose that the value is set in java.conf file, so I'm pasting it here (I've installed JDK 6 &amp; 7 on /usr/lib/jvm):</p>
  
  <pre><code># System-wide Java configuration file                                -*- sh -*-
  #
  # JPackage Project &lt;http://www.jpackage.org/&gt;
  
  # Location of jar files on the system
  JAVA_LIBDIR=/usr/share/java
  
  # Location of arch-specific jar files on the system
  JNI_LIBDIR=/usr/lib64/java
  
  # Location for noarch jar files using arch-specifics jar files
  JAVAJNI_LIBDIR=/usr/share/java-jni
  
  # Root of all JVM installations
  JVM_ROOT=/usr/lib/jvm
  
  # You can define a system-wide JVM root here if you're not using the
  # default one.
  #
  # If you have the a base JRE package installed
  # (e.g. java-1.6.0-openjdk):
  #JAVA_HOME=$JVM_ROOT/jre
  #
  # If you have the a devel JDK package installed
  # (e.g. java-1.6.0-openjdk-devel):
  #JAVA_HOME=$JVM_ROOT/java-1.7.0-openjdk-1.7.0.9.x86_64
  JAVA_HOME=$JVM_ROOT/openjdk-6.0.24
  
  # Options to pass to the java interpreter
  JAVACMD_OPTS=
  </code></pre>
  
  <p>By just commenting and uncommenting the corresponding lines in java.conf, it turns that ant is working fine with 7 and fails with 6. when I echo JVM_LIBDIR just before <code>java</code> command in the ant shell, I receive <code>user/share/java</code> as stated in java.conf. But <code>ant --execdebug</code> has returned something strange: <code>JVM_LIBDIR /usr/lib/jvm-exports/openjdk-6.0.24</code>. What is that and how can I fix it? </p>
  
  <p>If you could not tell the problem here, what is the neatest and safest way to install multiple versions of JDK, that can be switched easily?</p>
  
  <p>Any help is well appreciated.</p>