ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Antonio, Jean Claude \(Spring IT\)" <jeanclaude.antonio-...@eds.com>
Subject RE: How to get user project properties from java app
Date Fri, 23 Dec 2005 11:08:05 GMT
It works like charms! Cheers Steve


-----Original Message-----
From: Stephen McConnell [mailto:mcconnell@dpml.net]
Sent: Thu 22/12/2005 21:05
To: 'Ant Users List'
Subject: RE: How to get user project properties from java app
 
 
You could try something like the following:

    Project createProject( File file ) 
    {
        Project project = new Project();
        project.setSystemProperties();
        project.setDefaultInputStream( System.in );
        project.setCoreLoader( getClass().getClassLoader() );
        project.addBuildListener( createLogger() );
        System.setIn( new DemuxInputStream( project ) );
        project.setProjectReference( new DefaultInputHandler() );
        ProjectHelper helper = ProjectHelper.getProjectHelper();
        project.addReference( "ant.projectHelper", helper );
        helper.parse( project, file );
        return project;
    }

A more complete example is shown on the following page.

http://svn.berlios.de/viewcvs/dpml/trunk/main/depot/tools/builder/src/main/n
et/dpml/tools/impl/StandardBuilder.java?view=markup

Cheers, Steve.


> -----Original Message-----
> From: Antonio, Jean Claude (Spring IT) 
> [mailto:jeanclaude.antonio-eds@eds.com] 
> Sent: Friday, 23 December 2005 4:16 AM
> To: user@ant.apache.org
> Subject: How to get user project properties from java app
> 
> Hello, 
> 
> I'm writing a java application that call ant.
> It works fine.
> But I want to get project properties defined in the build.xml file.
> 
> With project.getUserProperty("serverName");
> or   project.getProperty("serverName");
> I get a returned null value.
> 
> ----------------------------------------------------------------
> <?xml version="1.0" encoding="ISO-8859-1"?> <project 
> name="InitialProject" basedir="." default="clear">
> 	    <property name="serverName"     value="localhost"/>
> 
> 
> Project project= new Project();
> ProjectHelper helper = new ProjectHelperImpl(); 
> project.init(); helper.parse(antProject, new File("build.xml"));
> 
> project.getUserProperty("serverName");
> 
> ----------------------------------------------------------------
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message