simply create file app.properties in src/main/resources with content like this
application.version=${project.version}
then enable maven filtering like this
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
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" );
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…