To embed information in a file you can use the standard copy task with an embedded filterset to put dynamic information into a source file.
Ant also supplies a buildnumber task that is useful to generating a sequential number each time ANT runs.
Finally I'd recommend looking at the 3rd party JReleaseInfo for an alternative mechanism that might be more useful to adopt (or emulate). It generates Java classes designed to to embedded in your code. The advantage of this approach is that you can lookup the version at runtime.