title: Execute a jar file using Ant
body: <p>I am trying to create a runnable jar file from java classes using ant. The java classes use external jars. When I execute the build.xml its showing class not found exception while running the java program. Its compiling fine.</p>
  
  <p>Part of My source code:</p>
  
  <pre><code>&lt;path id="project-libpath"&gt;
     &lt;fileset dir="${lib.dir}"&gt; 
        &lt;include name="*.jar"/&gt;
     &lt;/fileset&gt; 
  &lt;/path&gt;
  
  &lt;path id="project-classpath"&gt;
     &lt;fileset dir="C:/xmldecode/lib"&gt;   
        &lt;include name="*.jar"/&gt;
     &lt;/fileset&gt; 
  &lt;/path&gt;
  
   &lt;target name="compile" depends="prepare"&gt;               
      &lt;javac srcdir="${src.dir}" destdir="${classes.dir}"&gt;    
         &lt;classpath refid="project-classpath"/&gt;
      &lt;/javac&gt; 
   &lt;/target&gt;
  
   &lt;target name="jar" depends="compile"&gt;
      &lt;copy todir="${classes.dir}"&gt;     
         &lt;fileset dir="C:/xmldecode/lib"/&gt;    
      &lt;/copy&gt;
  
      &lt;pathconvert property="mf.classpath" pathsep=";"&gt; 
         &lt;path refid="project-classpath" /&gt; 
         &lt;flattenmapper /&gt; 
      &lt;/pathconvert&gt; 
  
      &lt;jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}"&gt;
         &lt;manifest&gt;
            &lt;attribute name="Main-Class" value="${main-class}"/&gt;
            &lt;attribute name="Class-Path" value="${mf.classpath}"/&gt; 
         &lt;/manifest&gt;
      &lt;/jar&gt;
   &lt;/target&gt;
  
  
   &lt;target name="run" depends="jar"&gt;
      &lt;java jar="${jar.dir}/${ant.project.name}.jar" fork="true"&gt;       
      &lt;/java&gt;
  </code></pre>