Skip to content

Instantly share code, notes, and snippets.

@Waxolunist
Last active March 26, 2020 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Waxolunist/4967241bd8c7a46a47c9170880280439 to your computer and use it in GitHub Desktop.
Save Waxolunist/4967241bd8c7a46a47c9170880280439 to your computer and use it in GitHub Desktop.

Answer to SO question 48693420

Demonstrates substitution in properties file with system variables.

Execute with

username=user1 password=pass1 mvn resources:resources && cat target/classes/development.properties

Expected output:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building question-48693420 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-cli) @ question-48693420 ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.555 s
[INFO] Finished at: 2018-02-15T08:48:50+01:00
[INFO] Final Memory: 10M/619M
[INFO] ------------------------------------------------------------------------

username=user1
password=pass1

# place in src/main/resources
username=${env.username}
password=${env.password}
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>question-48693420</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment