Here is what I think is the best way to perform one or the other targets in an ant file depending on if a property is set or not.
Let us pretend that if the mainclass property has a value we want to create an executable JAR-file, if not set we will create a plain JAR-file.
Create a jar-file of the projects classes
description="--> Create a JAR-file of the project classes."
<target name="executable-jar" if="mainclass">
<target name="plain-jar" unless="mainclass">
It is dead simple but still, I've seen a lot of strange
antcallwith conditions and stuff in the wild to acheive the same thing.
Another little smippet that took a while to get right is to create a class-path in the
MANIFEST.MFbased on an ANT-path.
This is the best way I have found so far, the silly thing is that it is different if building on windows or on a real operating system.
<pathconvert dirsep="/" pathsep=" " property="manifest-classpath" refid="build.classpath">
The regexp when building on unix is:
This will set the
manifest-classpathproperty with a value that is suitable for writing in the Manfest attribute
Class-Path. In this example it will prefix all path-entries with a
lib/but you can take it from here yourselves :-)
It is a sad state of affairs; My friend still has not started a blog.