Search code examples
mavenenvironment-variablesmaven-3maven-antrun-plugin

Why isn't Maven recognizing my environment variables?


I’m Using Maven 3.3.3 on Mac Yosemite with Java 8. I have defined a variable, JBOSS_HOME, in my /etc/profile file …

JBOSS_HOME=/opt/wildfly-10.0.0.CR2 

In my terminal (using bash shell), I can see the value of this variable …

davea$ echo $JBOSS_HOME
/opt/wildfly-10.0.0.CR2

However, when I run my Maven script (from the same shell), I can’t access the value of this variable. The below

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <dependencies>
        <dependency>
            <groupId>ant-contrib</groupId>
            <artifactId>ant-contrib</artifactId>
            <version>20020829</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>create-dodeploy-file</id>
            <phase>package</phase>
            <configuration>
                <target>
                    <taskdef resource="net/sf/antcontrib/antcontrib.properties" />
                    <property environment="env" />
                    <echo message="jboss home: ${env.JBOSS_HOME}" />

produces …

 [echo] jboss home: ${env.JBOSS_HOME}

What gives? How do I get Maven to recognize my environment variables?


Solution

  • When I added this line at the top of my ~/.profile file

    export JBOSS_HOME=$JBOSS_HOME
    

    Then the Maven script picked up the environment variable. Intuitive, eh?