Activate Maven Profile by OS
June 05, 2021
We can activate Maven profile by OS settings using <os>
element within <activation>
parent element. When the Maven build runs on the operating system which is configured in Maven profile, then that profile will be activated automatically.
The
<os>
element within <activation>
parent element is used as following.
<activation> <os> <name>Windows XP</name> <family>Windows</family> <arch>x86</arch> <version>5.1.2600</version> </os> </activation>
<os> Element
The<os>
element is used within <activation>
parent element. The <os>
element defines the same parameters as defined by <requireOS>
element used by Maven enforcer plugin.
The
<os>
tag can have following sub-tags.
<os> <name></name> <family></family> <arch></arch> <version></version> <display></display> <message></message> </os>
2. <family> : The family of OS such as dos, mac, netware, os/2, tandem, unix, windows, win9x, z/os, os/400 .
3. <arch> : CPU architecture.
4. <version> : The version of the OS.
5. <display> : Flag to display the detected OS information.
6. <message> : An optional message to the user in case of fail.
Find the sample Maven code with a profile that will be activated by OS settings.
pom.xml
<project> ------ <profiles> <profile> <id>os_profile</id> <activation> <os> <name>Windows XP</name> <family>Windows</family> <arch>x86</arch> <version>5.1.2600</version> </os> </activation> <build> <resources> <resource> <directory>src/main/resources/old-files</directory> </resource> </resources> </build> </profile> ------ </profiles> </project>
References
Introduction to Build ProfilesRequire OS Version