A Build profile is known as a set of configuration values used to set or override default values. To build profile with Maven, you need to customize build for different environments such as Production v/s Development environments.
While building profiles you need to specify in pom.xml file using its active Profiles/profiles elements and are triggered in different ways. You can modify the POM at build time, and are used to give parameters different target environments like development, testing, and production environments.
Build profiles are majorly of three types.
|Type||Where it is defined|
|Per Project||Defined in the project POM file, pom.xml|
|Per User||Defined in Maven settings xml file (%USER_HOME%/.m2/settings.xml)|
|Global||Defined in Maven global settings xml file (%M2_HOME%/conf/settings.xml)|
A Maven Build Profile can be executed in various ways.
Here’s the following directory structure of your project −
Now, under src/main/resources, there are three environment specific files −
|Sr.No.||File Name & Description|
Explicit Profile Activation is explained in the following example, where we attach maven-antrun-plugin:run goal to test the phase. We can allow to echo text messages for different profiles. For this use pom.xml to define different profiles and will activate profile at command console using maven command.
Assume, we've created the following pom.xml in C:\MVN\project folder.
And assume, we've created following properties file in C:\MVN\project\src\resources folder.
Let’s open the command console and go to the folder containing pom.xml and execute the following mvn command. Now pass the profile name as argument using -P option.
Maven will start processing and displaying the result of test build profile.
You can perform the following steps −
Let’s open the command console, go to the folder containing pom.xml and execute the following mvn commands. Pass the profile names as argument using -P option.
Check the output of the build to see the difference.
To activate the profile open Maven settings.xml file available in %USER_HOME%/.m2 directory where %USER_HOME% represents the user home directory. If settings.xml file is not there, then create a new one.
Then add test profile as an active profile using active Profiles node as shown below in example.
Let’s open command console, go to the folder containing pom.xml and execute the following mvn command. But not pass the profile name using -P option. Then Maven will showcase the result of test profile being an active profile.
Here you can remove active profile from maven settings.xml and update the test profile mentioned in pom.xml. You can add activation element to profile element as mentioned below.
The test profile will trigger when the system property "env" is specified with the value "test". Create an environment variable "env" and set its value as "test".
Now open command console, go to the folder containing pom.xml and execute the following mvn command.
You can activate the element to include os detail as mentioned below. This test profile will trigger when the system is windows XP.
Now open command console, go to the folder containing pom.xml and execute the following mvn commands. Do not pass the profile name using -P option. Maven will display result of test profile being an active profile.
To activate via present/missing file can be as shown below. The test profile will trigger when target/generated-sources/axistools/wsdl2java/com/companyname/group is missing.
Go command console and open then go to the folder containing pom.xml and execute the following mvn commands. But never pass the profile name using -P option. Maven will display result of test profile being an active profile.
Maven Related Interview Questions
|Java Script Interview Questions||Adv Java Interview Questions|
|Core Java Interview Questions||Java Interview Questions|
|Maven Interview Questions||Jenkins Interview Questions|
|Java collections framework Interview Questions||JUnit Interview Questions|
|Java 8 Interview Questions||Apache Ant Interview Questions|
|Svn Subversion Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.