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
If you want to have multiple profiles in your Spring Boot project, by using the YAML file you just need to define one configuration file and put configuration data of specific profile into it, but if you use properties file you need to define individual file for each profile.
Properties can be defined in a POM or in a Profile. The properties set in a POM or in a Maven Profile can be referenced just like any other property available throughout Maven. User-defined properties can be referenced in a POM, or they can be used to filter resources via the Maven Resource plugin.
@Value("${applicationName}")
private String applicationName;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With