Bug 39554

Summary: Make sysproperty a top level element to set system properties of ant
Product: Ant Reporter: Oliver Meyer <omeyer>
Component: Core tasksAssignee: Ant Notifications List <notifications>
Status: NEW ---    
Severity: enhancement    
Priority: P4    
Version: 1.6.5   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Oliver Meyer 2006-05-11 09:01:35 UTC
I'd like to be able to define java system properties in the build.xml file. For
example I need to set a proxy (socksProxyHost) for the <scp> task that runs
within the virtual machine ant runs in. Until now, the only way to do this is to
give the properties to the ant call itself or define it for my ant installation.
But I want to define them in the build.xml file itself.

A simple way to do this would be to allow the <sysproperty> element as a direct
child of the <project> element. Evaluating the element would call
System.getProperties.setProperty(key, value) making that system property
available for all other tasks withing ant.
Comment 1 Steve Loughran 2006-05-11 09:35:47 UTC
For the particular problem of proxy setup (and it is a problem, especially on
roaming laptops), what is wrong with the <setproxy> task?
Comment 2 Oliver Meyer 2006-05-11 10:35:00 UTC
The only problem with <setproxy> is that I did not look for something like that
:-) Thanks, it solved my problem, so I'm reducing priority for this enhancement.
It still sounds like a good idea to me, though, so the enhancement is still open.
Comment 3 Stephen White 2010-04-12 13:25:13 UTC
We have found a need for something similar, to configure the XML parser that underlies an operation for which we use the <xslt> task.

We have a pretty trivial ant task implementation that allows us to invoke:

<setSystemProperty key="org.apache.xerces.xni.parser.XMLParserConfiguration" value="org.apache.xerces.parsers.XIncludeParserConfiguration" />

prior to XSLT, and this then allows us to convert docbook (with xincludes) to HTML using ant's xslt task.

No doubt there are other inventive uses for being able to set system properties, so we'd like to add a +1 to having this as a standard feature in ant.

For the record, or for anyone else that wants something similar, our task is implemented as:

/** A simple Ant task to set a System property. */
public class SetProp extends Task {
  private String _key = null;
  private String _value = null;

  public void execute() throws BuildException {
    System.setProperty(_key, _value);
  }

  public void setKey(final String key) {
    _key = key;
  }

  public void setValue(final String value) {
    _value = value;
  }
}