Is there a way to use maven property in Java class during compilation

simply create file in src/main/resources with content like this


then enable maven filtering like this


That’s all – in app code just read properties file

ClassPathResource resource = new ClassPathResource( "" );
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" );

Leave a Comment