Add M2_HOME, M2, MAVEN_OPTS to environment variables. Set the environment variables using system properties. Open command terminal and set environment variables. Open command terminal and set environment variables.
Note that if you want to use Maven, you need to have Java installed and an environment variable set up. Open Google and search for maven download.
Set M2_HOME & PATHCreate an environment variable named M2_HOME which refers to directory where maven was untarred/ unzipped. and then add this variable to PATH environment variable. $>export PATH=$M2_HOME/bin:$PATH. Click OK, then Edit the 'Path' user variable to add M2_HOME\bin folder in it.
Check out the Maven Properties Guide...
As Seshagiri pointed out in the comments, ${env.VARIABLE_NAME}
will do what you want.
I will add a word of warning and say that a pom.xml
should completely describe your project so please use environment variables judiciously. If you make your builds dependent on your environment, they are harder to reproduce
It might be safer to directly pass environment variables to maven system properties. For example, say on Linux you want to access environment variable MY_VARIABLE. You can use a system property in your pom file.
<properties>
...
<!-- Default value for my.variable can be defined here -->
<my.variable>foo</my.variable>
...
</properties>
...
<!-- Use my.variable -->
... ${my.variable} ...
Set the property value on the maven command line:
mvn clean package -Dmy.variable=$MY_VARIABLE
Also, make sure that your environment variable is composed only by UPPER CASE LETTERS.... I don't know why (the documentation doesn't say nothing explicit about it, at least the link provided by @Andrew White), but if the variable is a lower case word (e.g. env.dummy), the variable always came empty or null...
i was struggling with this like an hour, until I decided to try an UPPER CASE VARIABLE, and problem solved.
OK Variables Examples:
(NOTE: I was using maven v3.0.5)
I Hope that this can help someone....
Can't we use
<properties>
<my.variable>${env.MY_VARIABLE}</my.variable>
</properties>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With