ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Laurent Morissette" <laurent.morisse...@gmail.com>
Subject [JAR task] adding JARS that are in a folder to another jar to create an executable jar of an application
Date Mon, 25 Dec 2006 01:28:51 GMT
Hey everybody,
I'm doing a project under eclipse 3.2 and i'm trying to write an ant file
that can be used on any other project and i'm having some troubles :)
So, to cut short on chit-chat, here my project structure:
-src folder with some sub packages
-lib folder containing tird party librairies such as log4j
-dist folder to put the generated JAR
ant.properties to store variables definition

Here are some snippets of my build file to hepl unsertand my probelem:

<!-- =================================
          target: Compile
         ================================= -->
    <target name="Compile" depends="Clean" description="Compile current
project">

        <echo>Compilation process started...</echo>

        <javac srcdir="${src.dir}" destdir="${class.dir}">
            <classpath location="${lib.dir }">
                <fileset dir="${lib.dir}">
                    <include name="**/*.jar" />
                </fileset>
            </classpath>

        </javac>


    </target>

This task is OK but the dist task does not work properly:

<!-- - - - - - - - - - - - - - - - - -
          target: dist
         - - - - - - - - - - - - - - - - - -->
    <target name="dist" depends="Compile">
        <mkdir dir="${dist.dir}" />



        <jar destfile="${dist.dir}\${executable}" basedir="${ class.dir} ">
            <fileset dir="${class.dir}" />
            <zipfileset dir="${lib.dir}">
             <include name="**/*.jar" />
            </zipfileset>


            <manifest>
                <attribute name="Manifest-Version" value="1.0" />
                <attribute name="Created-By" value="L. Morissette" />
                <!--attribute name="Class-Path" value="${classpath} "/-->
                <attribute name="Main-Class" value="${mainClass}" />
            </manifest>
        </jar>

    </target>

This correctly add my libs into "${executable}" but when I try to run it, I
get the following exception :

Exception in thread "main" java.lang.NoClassDefFoundError :
org/apache/log4j/Logger
        at LogTest.<clinit>(Unknown Source)
        at MainClass.main(Unknown Source)

(assuming that I'm using log4j third-party lib)

I've seen somewhere that it was necessary to define a Class-Path entry to
the MANIFEST,MF file, so i've  created a task setClassPath:

<!-- - - - - - - - - - - - - - - - - -
          target: setClassPath
         - - - - - - - - - - - - - - - - - -->
    <target name="setClassPath">
        <echo>Setting classPath</echo>
        <pathconvert property="classpath" pathsep=" ">
            <path>
                <fileset dir="${lib.dir}" includes="*.jar,*.zip" />
            </path>
            <map from="${lib.dir}" to="." />
        </pathconvert>


    </target>
But this does'nt work either, so what did I do wrong ?

Any help would be welcome :)


P.S: for those who might ask why i'm not using Netbeans, the reason is
simple, I have a restriction to use only Eclipse and I want to be able to
use my buildfile in any other projects with same structure whitout having to
chand anything to the script base :)

Oh and I almost forgot, in a old project I specified all the libs myself and
it worked fine ??!!!!




Thank again :)

-- 
Laurent Morissette
---------------------------
Software Engeneer, CGI

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message