14

I'm trying to extract some properties from Maven and print them when my app starts. I'm using Spring Boot so the resource filtering is automatically done for me.

In my application.yml I have the following

  applicationName: "@project.artifactId@"
  buildVersion: "@project.version@"
  buildTimestamp: "@maven.build.timestamp@"

When I run this on IntelliJ, I get the desired result, my properties are populated and printed as expected (single quotes have the same result) Removing the quotes will give me an Exception from SnakeYaml regarding the use of the '@' character

When I run this on Cent-OS though, via a jar (java -jar blah..blah) the properties are not being resolved but are instead being treated as Strings and instead of the correct version numbers etc, what gets printed are the strings inside the quotes above.

Any ideas on how to fix this? Is it related to the way I run the jar?

I used this as an example

Anthon
  • 69,918
  • 32
  • 186
  • 246
mariosk89
  • 944
  • 1
  • 11
  • 31
  • This is something odd... Recently I tested this and works fine, maybe this depends of `spring-boot` version... What version are you using? – JUAN CALVOPINA M Jun 06 '17 at 17:48
  • I'm using 1.5.1 . I ended up adding an additional properties file using Spring's properties format instead of Yaml – mariosk89 Jun 07 '17 at 11:46

2 Answers2

1
@Value("${applicationName}")
private String applicationName;
Zoe
  • 27,060
  • 21
  • 118
  • 148
Myjay1516
  • 197
  • 2
  • 4
  • 12
-1

you could get them programatically with getClass().getPackage().getImplementationVersion() and alike.

sschrass
  • 7,014
  • 6
  • 43
  • 62
  • the question is about maven properties and not class package information (which is required the declaration in a dedicated package-info.class) – herau Dec 18 '19 at 16:53