Ant Build fails in Eclipse

I was creating a jar file of my project using ANT after googling how to do it, I named this inkpot. Below is the build.xml file.

<?xml version="1.0" ?> 
<project name="ExcelData" default="compress">

    <target name="init">
        <mkdir dir="build/classes" />
        <mkdir dir="dist" />
    </target>

    <target name="compile" depends="init">
        <javac srcdir="src" destdir="build/classes" />
    </target>

    <target name="compress" depends="compile">
            <jar destfile="dist/ExcelData.jar" basedir="build/classes" />
    </target>

    <target name="execute" depends="compile">
        <java classname="com.spt.excel.data.ExcelData" classpath="build/classes" />
    </target>

    <target name="clean">
        <delete dir="build" />
        <delete dir="dist" />
    </target>

</project>

      

but the problem is that the ANT building is not working. But I am getting errors like

D:\Eclipse\workspace\ExcelData\src\com\spt\excel\data\ExcelData.java:24: error: package org.slf4j does not exist`

      

And links to this link to install tools.jar.

Can someone tell me where I am going wrong. Thank you in advance.

+3


source to share


2 answers


you have no include libraries for your ant file, I mean the classpath, just add all the libs your eclipse project contains to the ant file and everything will work and please read the original tutorial like this one

like

<javac srcdir="${src.dir}" destdir="${classes.dir}">
    <classpath>
        <pathelement location="${lib.dir}/lib1.jar"/>
        <pathelement location="${lib.dir}/lib2.jar"/>
    </classpath>
</javac>

      

for libs



<path id="mylibs">
    <fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>

<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="mylibs" debug="on"/>

      

add properties lib.dir

 <property name="lib.dir"  location="{here is path to your libraries}"/>

      

+5


source


For Eclipse, I recommend the following:

Right click your project -> Export -> Runnable Jar file 

Pick launch configuration, destination, extract required libraries into JAR, tick Save as ANT script

Finish.

      

Eventually you will have a Jar file generated along with a reusable Ant script.



Then you parse your Ant script.

Difference between extracting and packaging libraries into a jar file

+2


source







All Articles