Maven-properties-filtering-like for Java annotations?

Currently, I know how to do this filtering using Maven:

pom.xml

<properties> <foo>bar</foo> </properties> 

app.properties

 foo=${foo} 

But is it possible to do this filtering using Maven, Spring or any other tool?

Myclass.java

 @MyAnnotation("${foo}") // ${foo} should get replaced at compile time public void getData() { return data; } 
+6
source share
1 answer

You tried to use resource plugin execution. As far as I know, you can point it to your Java source and use its normal filtering.

http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

  <properties> <my.name>chad</my.name> <java.property>//comment</java.property> </properties> <build> <sourceDirectory>target/processed-source/java</sourceDirectory> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> <resource> <directory>src/main/java</directory> <filtering>true</filtering> <targetPath>../processed-source/java</targetPath> </resource> </resources> </build> 

So, the first thing that you direct the processed java source to a special folder in the destination directory. Then you need to reconfigure the compiler plugin to NOT compile the unfiltered source and instead compile the new source. Please note that, like all maven stuff, you can customize a lot more than that.

This is a blog post .

+7
source

All Articles