Reputation: 1313
For a SpringBoot app :
I have resources in src/main/resources
: it can be JSON, XML... doesn't matter
Some resources are dynamic, for example :
{
"url": "${propA.url}"
}
This propA.url
is defined in application.properties
:
propA.url=http://localhost
Is it possible when building the project to finally having the real value after mvn package
:
{
"url": "http://localhost"
}
After compilation, it does not work.
Upvotes: 0
Views: 43
Reputation: 51
The properties-maven-plugin can do this. In pom.xml:
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>src/main/resources/application.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
...
Then the maven-resources-plugin will by default replace, for example, src/main/resources/app.json file if put like this:
{
"url": "@propA.url@"
}
Executing:
mvn package && less -FX target/classes/app.json
Will give you (if using the application.properties you mention above):
{
"url": "http://localhost"
}
Upvotes: 1