Listing F: Task to set environment variables
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Project;

public class SimplePropertyTask extends Task {
  private String name;
  private String value;

  public void execute() throws BuildException {
        if ((name != null) && (value != null)) {
            if (project.getProperty(name) == null) {
                project.setProperty(name, value);
                log("Added property: " + name);
            } else {
                log("Property already set for " + name);
            }

        } else {
               log("Name or Value was not set. Can't add property.");
        }
  }
  public void setName(String name) {
    this.name = name;
  }
  public void setValue(String value) {
    this.value = value;
  }
}