Search code examples
linuxmaven-2variablesenvironmentsetting

Setting environment variable with maven 2.x


Is it possible to set environment variable with maven (OS: Linux)?

I already have user-defined properties (in the pom and in profiles.xml)....my problem is, how to execute following from Maven

export GGA_FRE=/path

So will be possible, that every developer can set his own path for the GGA_FRE.


Solution

  • This answer is not correct, at least not completely (see comments).
    Unfortunately I can't delete it as it has been accepted. Your milage may vary.


    Use the exec:exec mojo.

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.1</version>
        <executions>
          <execution>
            <id>exportVar</id>
            <phase>initialize</phase>
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <executable>export</executable>
          <arguments>
            <argument>GGA_FRE=${my.path}</argument>
          </arguments>
        </configuration>
      </plugin>
    

    now call it like this mvn install -Dmy.path=/var/users/groucho