Get environment variables : Environment « Ant « Java

Get environment variables

<?xml version="1.0"?>
<project name="Template Buildfile" default="compile" basedir=".">
  <property name="dir.src" value="src"/>
  <property name="" value="build"/>
  <property environment="env"/>

  <target name="checkProperties">
    <fail unless="env.TOMCAT_HOME">TOMCAT_HOME must be set</fail>
    <fail unless="env.JUNIT_HOME">JUNIT_HOME must be set</fail>
    <fail unless="env.JBOSS_HOME">JBOSS_HOME must be set</fail>

  <!-- Creates the output directories -->
  <target name="prepare" depends="checkProperties">
    <mkdir dir="${}"/>

  <target name="clean"
          description="Remove all generated files.">
    <delete dir="${}"/>

  <target name="compile" depends="prepare"
          description="Compile all source code.">
    <echo>Compile code...</echo>



Related examples in the same category

1.Set system properties in Ant build script
2.Environment: ant home, OS and Processor