I just want to use maven placeholder in my Java class at compile time in order to reduce duplication.
Something like that:
pom.xml
simply create file app.properties in src/main/resources with content like this
application.version=${project.version}
then enable maven filtering like this
src/main/resources
true
That's all - in app code just read properties file
ClassPathResource resource = new ClassPathResource( "app.properties" );
p = new Properties();
InputStream inputStream = null;
try {
inputStream = resource.getInputStream();
p.load( inputStream );
} catch ( IOException e ) {
LOGGER.error( e.getMessage(), e );
} finally {
Closeables.closeQuietly( inputStream );
}
and provide method like this
public static String projectVersion() {
return p.getProperty( "application.version" );
}