Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant Build Failed in Eclipse

Tags:

java

ant

I was building an jar file of my project using ANT after searching in Google found how do do it i referred this ink. Below is my 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 the ANT building is failing. But i am getting errors as

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

And referred this link to set tools.jar.

Can Anyone tell me where i am going wrong. Thank You in advance.

like image 771
Rithesh Avatar asked Aug 20 '26 15:08

Rithesh


2 Answers

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

like that

<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}"/>
like image 53
Sergii Zagriichuk Avatar answered Aug 22 '26 06:08

Sergii Zagriichuk


For Eclipse I recommend 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 would have Jar file generated together with reusable Ant script.

Then you analyze your Ant script.

Difference between extracting and packaging libraries into a jar file

like image 22
Nikolay Kuznetsov Avatar answered Aug 22 '26 05:08

Nikolay Kuznetsov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!