ant jar/fileset propblems

Discussion in 'Java' started by Miguel De Anda, Jun 28, 2003.

  1. I have the following code in my build file.

    <property name="dist" location="dist"/>

    <target name="buildsource" depends="init" description="Builds source
    <jar destfile="${dist}/${date}_src_${dist.basename}.jar">
    <fileset dir=".">
    <exclude name="${dist}/**"/>

    The problem I'm getting is that it seems to ignore the excludes. How do I do
    this? I'm actually trying to exclude 4 folders but I removed them to keep it
    short. It basically gives me an error the second time I run it, saying that
    its trying to include itself (itself is in dist).
    Miguel De Anda, Jun 28, 2003
    1. Advertisements

  2. Ok, I give up. Can somebody please help me set up my build file? This is
    what I have now, and this is what I'm trying to do:

    clean - deletes folders created in init
    test - runs the test/driver class
    compile - compiles java code into dist folder
    dist - creates 3 jars, one with source and including all files not in
    any folders created by init
    the second with only the binary stuff, so everything inside the
    ${dist} folder
    the third that is pretty much a copy of everything except the
    ${dist} folder.

    These are the problems I'm getting:
    1) In distSrc and dist seem to try to include themselves in the jar. They
    must be ignoring my excludes or something.
    2) In distSrc, It either doesn't keep the directory stucture the same way or
    it includes other stuff.

    My basic directory structure is usually like this:
    root- build.xml and any other files created by JBuilder
    - /src folder with source files
    - /lib folder with jars to use in its classpath
    - /dist folder with any previous builds
    - /bak folder which I don't care about, JBuilder seems to create it.
    - /classes folder where the java code is compiled to.

    I've included my build file for reference. Thanks guys.

    Generic build file created by Miguel De Anda.

    Expects java source in ${src}
    Includes any jars in ${lib}
    Builds class files to ${build}
    Builds jar files to ${dist}
    Jar files are named ${date}_[src|bin|archive]_${dist.basename}
    Creates javadocs to ${docs}
    Tests using ${driver}

    Normal Targets are:
    test To test using ${driver}
    compile To compile only
    javadoc To create javadocs
    dist To create src, binary and archive jars
    all Same as dist
    clean Erases files in build and docs

    Last Updated June 17, 2003
    <project name="MyProject" default="usage" basedir=".">
    <property file="" />
    <property name="lib" value="lib" />
    <property name="src" value="src" />
    <property name="docs" value="doc" />
    <property name="build" value="classes" />
    <property name="dist" value="dist" />

    <!-- Most likely, nothing below needs to be modified. -->

    <target name="usage" description="Tells you how to use this build file">
    <echo message="Build file usage:" />
    <echo message="----------------------------------------" />
    <echo message="all See dist" />
    <echo message="clean Erases build and docs folders" />
    <echo message="compile Compiles code only" />
    <echo message="dist Creates a distribution/archive" />
    <echo message="javadoc Creates javadocs" />
    <echo message="test Compiles and tests the code" />

    <target name="init">
    <mkdir dir="${build}" />
    <mkdir dir="${dist}" />
    <mkdir dir="${lib}" />
    <mkdir dir="${docs}/api" />
    <format property="date" pattern="yyyy-MM-dd" />

    <target name="compile" depends="init" description="Compile source.">
    <javac srcdir="${src}" destdir="${build}" debug="true" debuglevel="lines">
    <fileset dir="${lib}">
    <include name="**/*.jar"/>

    <target name="distSrc" depends="clean,init" description="Builds source
    distribution package">
    <jar destfile="${dist}/${date}_src_${dist.basename}.jar">
    <fileset dir=".">
    <exclude name="${dist}/**"/>
    <exclude name="${docs}/**"/>
    <exclude name="${lib}/**"/>
    <exclude name="${build}/**"/>
    <exclude name="bak"/>
    <exclude name="**/*.jar"/>

    <target name="distBin" depends="compile" description="Builds binary
    distribution package">
    <jar destfile="${dist}/${date}_bin_${dist.basename}.jar"
    <attribute name="Main-Class" value="${driver}" />

    <target name="dist" depends="distSrc, distBin, javadoc">
    <jar destfile="${dist}/${date}_archive_${dist.basename}.jar" basedir="."
    excludes="**/*.jar,bak/**" />

    <target name="test" depends="compile">
    <java classname="${driver}" fork="yes">
    <pathelement location="${build}"/>
    <fileset dir="${lib}">
    <include name="**/*.jar"/>

    <target name="javadoc" depends="init" description="Builds the javadocs for
    the project">
    <javadoc destdir="${docs}/api" author="true" version="true">
    <fileset dir="${src}" />

    <target name="all" depends="dist" />

    <target name="clean" description="Cleans the binary files, javadocs, and
    jar packages">
    <delete dir="${build}" />
    <delete dir="${docs}" />

    Miguel De Anda, Jul 3, 2003
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnold Peters
    Arnold Peters
    Jan 5, 2005
  2. Replies:
    Tony Morris
    Mar 3, 2006
  3. Replies:
    Feb 10, 2007
  4. Andrew  McGhie
    Roedy Green
    Feb 7, 2008
  5. Justin Smith

    Propblems with pp

    Justin Smith, Dec 31, 2007, in forum: Perl Misc
    Peter Makholm
    Jan 3, 2008

Share This Page