version control - How to insert revision number of Java code file in to Java class file -
java code file contains @author , @version tags. version tag has information revision number of file. information resides in comments. there compilation flag or other mechanism available can add information .class file?
short answer: compiler ignores javadoc other forms of comments.
long answer: need write application copy existing @author authorname
, @version versionstring
javadoc elements above class/method declarations, such as:
@author({"authorname", "otherauthor"}) @version("versionstring") public class [...] { [...] }
an example author
annotation be:
@author("afk5min") @target({ elementtype.annotation_type, elementtype.constructor, elementtype.method, elementtype.type }) @retention(retentionpolicy.class) public @interface author { string[] value(); }
this way, each annotation present in resulting class file , may accessed.
9.6.3.2. @retention
annotations may present in source code, or may present in binary form of class or interface. annotation present in binary form may or may not available @ run time via reflection libraries of java se platform. annotation type java.lang.annotation.retention used choose among these possibilities.
additionally, retentionpolicy.runtime
may specified if desire runtime access annotations. reflection api allows this:
author.class.getannotation(author.class).value()[0] -> "afk5min"