I wrote a small BeanShell script that replaces \"__LINE__\"
with the actual line number in source code. It works well in Ant.
I am looking for a way to
Filtering source code was still tricky some months ago, but there's now a standard plugin at the MOJO project. You can now do that with a classic plugin declaration.
To filter source code (for example, when you'd like to have a constant in your Java code to retrieve the project version or artifactId), you should now use the templating-maven-plugin.
Put your code that should be filtered during the build under src/main/java-templates
as you would normally do under src/main/java
for non filtered sources. Use ${project.version}
or whatever property coming from the POM in your code.
Just put something like:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<version>1.0-alpha-3</version> <!-- Be sure to use the last version. Check on the website's plugin -->
<executions>
<execution>
<id>filter-src</id>
<goals>
<goal>filter-sources</goal>
</goals>
</execution>
</executions>
</plugin>
Be done :-). The code you put inside src/main/java-templates
gets filtered and added to the classpath.
The usage is very straightforward (see the example here).
This respects far better the idea of convention over configuration of Maven. You're basically replacing tens of XML lines and some hacks to get something done cleanly.
Side note: this works fine with Eclipse for example.