Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if a environment variable exists in my pom.xml?

If someone runs my pom.xml they get a nasty error because an environment variable is not defined. I would like to trap this and show a more straightforward error so that the problem can be easily fixed by defined the environment variable. I know probably not a good idea to have an environment variable in the pom, but this time I really need to. Any clues?


The variable is JAVA_6_HOME, the path to JDK6 since my default one is JDK7

like image 488
JohnPristine Avatar asked Dec 05 '22 09:12

JohnPristine


1 Answers

Maven-enforcer-plugin can do it:

<build>
   <plugins>
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.3.1</version>
        <executions>
           <execution>  
              <id>enforce-property</id>
              <goals>
                 <goal>enforce</goal>
              </goals>
              <configuration>
                 <rules>
                   <requireEnvironmentVariable>
                      <variableName>JAVA_6_HOME</variableName>
                      <message>JAVA_6_HOME system variable must be set!</message>
                   </requireEnvironmentVariable>
                 </rules>
                 <fail>true</fail>
              </configuration>
           </execution>
        </executions>
     </plugin>
  </plugins>
</build>
like image 194
Jk1 Avatar answered Jan 06 '23 13:01

Jk1