пʼятницю, 9 травня 2014 р.

How to set custom system environment variables using Maven?

How to set custom system environment variables using Maven?
Interenet replete with questions about how to set the system variables using Maven pom.xml and generously distributed tips:
on how to read these same system variables using Maven,
or how to override the variables via the command line parameters during launching mvn.

But how to set system variables via pom.xml?

I found at least one way to set environment variables using the maven-antrun-plugin (with help of this plugin you can do almost everything that and with help of command line shell like cmd)
You have the opportunity same as to specify a specific path to directory and as assign specific values, to become fully acquainted with this wonderful opportunity please check out with the manual
And I also give the simple example:

 <plugin>  
  <groupid>org.apache.maven.plugins</groupid>  
  <artifactid>maven-antrun-plugin</artifactid>  
  <version>${antrun.apache.version}</version>  
  <executions>  
  <execution>  
   <id>copy-app-set-system-variables</id>  
   <phase>pre-clean</phase>  
   <configuration>  
    <target>  
    <property environment="env">  
     <exec executable="${basedir}\external_resources\scripts\copy_app.cmd">  
     <env key="JAVA_HOME" path="${env.JAVA_HOME}" />  
     <env key="JAVA_JRE" path="${env.JAVA_HOME}\bin" />  
     <env key="LOG4J" path="${basedir}\external_resources\apache-tomcat-6.0.37_project_settings\log4j.xml" />  
     <env key="TOMCAT_HOME" path="${basedir}\external_resources\apache-tomcat-6.0.37" />  
     <env key="CATALINA_OPTS" value="-server -Xmx2048m -Xms1024m -XX:MaxPermSize=512m" />  
     <env key="env" value="${env.ENV}" />  
     <env key="CATALINA_HOME" path="${basedir}\external_resources\apache-tomcat-6.0.37" />  
     </exec>  
    </property>  
    </target>  
   </configuration>  
   <goals>  
    <goal>run</goal>  
   </goals>  
  </execution>  
  </executions>  
 </plugin>  



useful links:
Ant Tasks Manual
Maven Properties Guide
Maven Properties