I just want to use maven placeholder in my Java class at compile time in order to reduce duplication.
Something like that:
pom.xml
The simplest way I know of doing that is to use Templating Maven Plugin.
Add plugin declaration to your pom:
org.codehaus.mojo
templating-maven-plugin
1.0.0
filter-src
filter-sources
filter-test-sources
If you're filtering main sources:
src/main/java-templates
src/main
.If you're filtering tests sources too:
src/test/java-templates
src/test
.Assuming that your sources contain valid placeholders like:
package some.company;
public class SomeVersion {
public static String getVersion() {
return "${project.version}"
}
}
Now when you compile
or test
your project, those placeholders should be already valued.
Hope it helps.