Execute a jar file using Ant

Posted by geetha on Stack Overflow See other posts from Stack Overflow or by geetha
Published on 2010-06-15T10:36:23Z Indexed on 2010/06/15 19:12 UTC
Read the original article Hit count: 257

Filed under:

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.

Part of My source code:

<path id="project-libpath">

<fileset dir="${lib.dir}"> 

<include name="*.jar"/>

</fileset> 
</path>

<path id="project-classpath">

<fileset dir="C:/xmldecode/lib"> 

<include name="*.jar"/>

</fileset> 
</path>

 <target name="compile" depends="prepare">        

 <javac srcdir="${src.dir}" destdir="${classes.dir}">

    <classpath refid="project-classpath"/>

 </javac> 

 </target>

   <target name="jar" depends="compile">

    <copy    todir="${classes.dir}">

    <fileset dir="C:/xmldecode/lib"/>

    </copy>

    <pathconvert property="mf.classpath" pathsep=";"> 

     <path refid="project-classpath" /> 

      <flattenmapper /> 

      </pathconvert> 

      <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
        <manifest>
            <attribute name="Main-Class" value="${main-class}"/>
            <attribute name="Class-Path" value="${mf.classpath}"/> 
        </manifest>
       </jar>
      </target>



               <target name="run" depends="jar">
                  <java jar="${jar.dir}/${ant.project.name}.jar" fork="true">

          </java>

© Stack Overflow or respective owner

Related posts about ant