3

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.

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
Rithesh
  • 135
  • 1
  • 2
  • 11

2 Answers2

5

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}"/>
Sergii Zagriichuk
  • 5,389
  • 5
  • 28
  • 45
2

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

Community
  • 1
  • 1
Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101
  • hi Nikolay i wanted, by using that build.xml one – Rithesh Feb 07 '13 at 05:59
  • Creating ant files from IDE like extracting and so on, do not provide knowledge how to create real build file, as result questions like that, I think, just for author, will be perfect to read docs from ant.apache.com and create MANUALLY build file. But your point is good, for solid developers :). Cheers! – Sergii Zagriichuk Feb 07 '13 at 06:00
  • @SergiiZagriichuk, if the OP has no experience in Ant, then generating valid Ant script first is the best. And then reading docs for each generated ant task. I personally did it this way. It is time saving :) – Nikolay Kuznetsov Feb 07 '13 at 06:06
  • @NikolayKuznetsov Yep, I am agree, it's saving time – Sergii Zagriichuk Feb 07 '13 at 06:08