In my previous post ‘Profile
Activation’, I explained how to activate a profile based on some properties.
For example,
<profile> <id>production</id> <activation> <property> <name>environment.type</name> <value>prod</value> </property> </activation> </profile>
‘production’ profile will be activated, if there is a
system property ‘environment.type’ with value ‘prod’.
You can also pass these variables at command line.
pom.xml
<?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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.selflearningjava</groupId> <artifactId>helloworld</artifactId> <packaging>jar</packaging> <version>1</version> <name>helloworld</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <profiles> <profile> <id>production</id> <activation> <property> <name>environment.type</name> <value>prod</value> </property> </activation> </profile> <profile> <id>testing</id> <activation> <property> <name>environment.type</name> <value>test</value> </property> </activation> </profile> <profile> <id>dev</id> <activation> <property> <name>environment.type</name> <value>dev</value> </property> </activation> </profile> </profiles> </project>
You can activate ‘testing’ profile by executing below
command.
mvn clean install -Denvironment.type=testing
You can activate ‘production’ profile by executing below
command.
mvn clean install -Denvironment.type=prod
No comments:
Post a Comment