ant jar/fileset propblems

M

Miguel De Anda

I have the following code in my build file.

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

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


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).
 
M

Miguel De Anda

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:

targets:
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="build.properties" />
<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>

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

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

<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"/>
</fileset>
</jar>
</target>

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

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

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

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

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

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

</project>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top