You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jon Schewe <jp...@mtu.net> on 2006/12/25 14:53:46 UTC

Re: [JAR task] adding JARS that are in a folder to another jar to create an executable jar of an application

Yeah, that's not going to work.  You can't include jars inside other
jars and expect them to be found.  Unless you use something like
one-jar.  http://one-jar.sourceforge.net/

On Sun, 2006-12-24 at 20:28 -0500, Laurent Morissette wrote:
> 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 :)
> 

________________________________________________________________________
Jon Schewe | http://mtu.net/~jpschewe
If you see a signature.asc file attached to the message this is my
digital signature.
See http://www.gnupg.org for more information.

For I am convinced that neither death nor life, neither angels 
nor demons, neither the present nor the future, nor any 
powers, neither height nor depth, nor anything else in all 
creation, will be able to separate us from the love of God that 
is in Christ Jesus our Lord. - Romans 8:38-39