rohanagarwal
rohanagarwal

Reputation: 834

Populate environment properties file using pom.xml proeprties

I want to fetch the artifactId from the pom.xml and use this artifactId to populate the properties file.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>xxxxx</groupId>
   <artifactId>fm-service</artifactId>
   <packaging>war</packaging>
   <version>x.x.x-SNAPSHOT</version>
</project>

application.preperties

email.subject = "ALERT - [artifactId from pom.xml]"

Is is possible to do so? If yes how, if no, then please suggest alternatives.

Upvotes: 1

Views: 832

Answers (1)

Seelenvirtuose
Seelenvirtuose

Reputation: 20658

Maven provides a way to filter resources.

First, the file application.properties has to be put into the src/main/resources directory. Then its content has to be:

email.subject = "ALERT - ${project.artifactId}"

Last (but not least) simply add this configuration to your POM:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

Now all files in the resources directory will be filtered, which means that all variables inside are resolved.

Upvotes: 4

Related Questions