Build numbers should be associated with a continuous integration server like hudson. Use different jobs for different branches/teams/distributions.
To keep the version number in the final build, I would recommend just using maven for build system. It will create a .properties file archived into the final .jar/.war/.whatever-ar on META-INF/maven///pom.properties. The .properties file will contain the version property.
Since I am recommending maven, I would urge you to check out the release plugin to prepare the release on source repository and keep the versions on sync.