In this Ant tutorial installment, we will use ant Properties to specify the work directory structure that will contain our .class and .jar files. The work directory structure tends to be a personal preference, and properties will allow us to centralize the structure definition so that any change will be relatively pain-free. We specify the directories with a location attribute, thereby binding the property to a file system location. This allows us to pass the property to another ant process without any local directory side effects.
clean-init: to remove the work directory structure.
all: the build roll-up target.
clean: to clean roll-up target.
Note that my target naming convention is to pair a target with a clean-target. I reserve the all and the clean targets as roll-up targets for all build and clean targets respectively.
2 properties:
obj-dir: the root directory for our .class files.
lib-dir: the root directory for our .jar files.
We can now execute the init target to create the work directories, and the clean-init target to remove the work directories.
BUILDSUCCESSFUL Totaltime:2 seconds $ ls build.xml
Now, let’s add targets to compile, jar and execute a java class. We’ll just copy over the hello.java class from our previous installment and place it in the src directory. The compile and jar targets from before remain largely the same; but we add the destdir attribute to the javac task to specify where the .class files are to be stored and we can remove the includes attribute from the jar task. Our new build.xml looks like this: