If you want to modify your .java files, or any other file, using maven or ant you can call an external program/script to modify the files for you.
Maven pom.xml example:
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>1234</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/scripts/modifyfiles.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
With ANT:
<target name="run">
<exec executable="name-of-executable">
<arg value="${arg0}"/>
<arg value="${arg1}"/>
</exec>
</target>
Eather way, you'll have to write an external script (create a runnable jar, python, shell script, exe...) to do what you want, like reading all .java files, looking for a string pattern, putting a string a line above...
Doing like this, your script will be called every time before compiling the source code.