On 22/08/05, Taner Diler <[EMAIL PROTECTED]> wrote: > > Hi, > > I try to get property that in defined in build.xml by using java. How > can I do that? > > build.xml > > <...> > <property name="property_1" value="1"/> > </...> > > and java code > > Project ant = new Project(); > ProjectHelper helper = new ProjectHelperImpl(); > ant.init(); > helper.parse(ant, new File(xmlFile)); > String property_1 = ant.getProperty("property_1"); > > When I run this code, Null is returned by "ant.getProperty("property_1")". > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > I have copy/pasted a source code from the ANT manual:
import org.apache.tools.ant.BuildException; public class Find extends Task { private String property; private String value; private String print; public void setProperty(String property) { this.property = property; } // setter for value and print public void execute() { if (print != null) { String propValue = *getProject().getProperty(print)*; log(propValue); } else { if (property == null) throw new BuildException("property not set"); if (value == null) throw new BuildException("value not set"); *getProject().setNewProperty(property, value)*; } } } I recommend you to go to the ant's site, then go to the manual link, Developing with Ant and the last tutorial is called "Tasks using Properties, Filesets & Patths" <http://ant.apache.org/manual/tutorial-tasks-filesets-properties.html> <http://ant.apache.org/manual/tutorial-tasks-filesets-properties.html> -- Regards, Petar!