Setting environment variable with maven 2.x
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
I don't think there is a Java way to set environment variable the way export command does (so that it is avaliable outside of Java). (see for example this question: How do I set environment variables from Java?)
However, you might hack you way around: for example use maven-exec plugin to run a shell script and then set the variable in the script. You might pass a parameter to your script to specify the variable value.(note that I have not tested this)