ant

Get the current SVN revision number in from Ant

Another minor Problem I struggled with the last couple times I was updating one of my build scripts was resolving the current SVN revision number from within ant. Google points out a few solutions, but most of them require optional SVN tasks or do an exec. Someone (sorry, I would put a link if I could remember) came up with the simple solution of using the stored SVN information from the filesystem. So:

    <loadfile property="svn.revision" srcFile="./.svn/entries">
        <filterchain>
        <headfilter lines="1" skip="3"/>
        <deletecharacters chars="\n"/>
        </filterchain>
   </loadfile>

loads the current revision number into a property called svn.revision. I use this with svn 1.4 and 1.5 repositories and it works just fine.

Tags: ,

Thursday, May 14th, 2009 Other No Comments

combine multiple jar files and remove signatures

I just came across a situation where I had to join multiple jar files and my own classes into one jar bundle. Ant comes in handy:

<jar destfile="${app.id}-${app.version}.jar"
  index="true"
  filesetmanifest="merge">
  <fileset dir="${classes.dir}"/>
  <zipgroupfileset dir="${lib.dir}" includes="*.jar" />
</jar>

This takes all the files in ${classes.dir}, packs them in a jar and add the content of all the jar files in ${lib.dir}. In this case, we merge multiple manifests, but this can be changed according to the jar task documentation.
› Continue reading

Tags: , ,

Wednesday, October 29th, 2008 Other 2 Comments

ANT build.xml template

Just that I have it at one place. This is my ant build.xml template. It assumes a simple project structure:

src/ - all java soources in here
lib/
  devel/ - development libraries
  runtime/ - runtime libraries

If your project follows this struicture, you can get the following tasks out of the box:

Buildfile: build.xml

Main targets:

 clean          Clean
 compile        Compile all source files
 compile-tests  Compile all source files
 dist           Build library and pack jar file
 dist-one       Build library and pack jar file
 doc            Create Javadoc
 html-reports   Creates HTML from test reports
 test           Run JUnit Tests
Default target: dist

You can modify the properties to adapt different names or a different project structure. The script creates a target directory that contains the results.

Compiling and packing should work out of the box, but the test sections expects a junit and ant-junit jars in lib/devel. They can also be placed in one of Ants lib directories.

The build file

Tags:

Wednesday, October 22nd, 2008 Other No Comments