You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Robert Koberg <ro...@koberg.com> on 2004/01/29 03:48:57 UTC

howto trigger an Ant build within java

Hi,

I am looking into using Ant (v1.6.0) more in my webapp so I can offer 
offline publishing equivalents. I am transforming some config XML into a 
build file. I then want to load that build file into a new 
org.apache.tools.ant.Project. The build.xml gets produce properly (it 
runs successfully from the command line).

How do I load the build file and create an ant project, then trigger a 
particular target to execute? The build file uses only Core Tasks (and 
an xmlcatalog). Is there a simple example somewhere? I have tried 
searching with google but getting too many hits that don't cover what I 
am looking for.

Here is what I have tried:

org.apache.tools.ant.Project antProject = new 
org.apache.tools.ant.Project();

AntXMLContext antContext = new AntXMLContext(antProject);

File f = lsbProject.lookup("build.xml").getFile();
System.out.println("build.xml: " + f);

antContext.setBuildFile(f);
System.out.println("project name: " + antContext.getCurrentProjectName());

Vector targets = antContext.getTargets();
for (Enumeration e = targets.elements(); e.hasMoreElements();) {
   Target target = (Target) e.nextElement();
System.out.println(target.getName() + " : " + target.getDescription());
}

----------
the System.outs produce:

build.xml: c:\home\app\projects\grok\build.xml
project name: null
  : null
----------

thanks for any help,
-Rob

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


Re: howto trigger an Ant build within java

Posted by Robert Koberg <ro...@koberg.com>.
[moving to dev list]

Jim Fuller wrote:

>>From: Robert Koberg [mailto:rob@koberg.com] 
>>Sent: 29 January 2004 02:49
>>To: user@ant.apache.org
>>Subject: howto trigger an Ant build within java
> 
> 
>>I am looking into using Ant (v1.6.0) more in my webapp so I can offer 
>>offline publishing equivalents. I am transforming some config 
>>XML into a 
>>build file. I then want to load that build file into a new 
>>org.apache.tools.ant.Project. The build.xml gets produce properly (it 
>>runs successfully from the command line).
> 
> 
> So the transformation of config file is happening in your app which
> ultimately generates a build file, which in turn you would like to
> simply run ant on ?

The configs are held in memory(jdom) and eventually I would like to use 
/something/ like a chained transformation to go from the configs to an 
ant build in memory and run the build on a user chosen target.  I would 
use the build file to present a 'nav' tree similar to what eclipse does. 
The user clicks on a target to do things like generate a 
site/folder/page or promote to a vhost stage (local or remote) based on 
their config.


> 
> 
>>How do I load the build file and create an ant project, then 
>>trigger a 
>>particular target to execute? The build file uses only Core 
>>Tasks (and 
>>an xmlcatalog). Is there a simple example somewhere? I have tried 
> 
> 
> Hello Rob,
> 
> If you are physically generating the build file then just use the
> launcher in the
> http://nagoya.apache.org/gump/javadoc/ant/build/javadocs/index.html
> org.apache.tools.ant.launch package. Though perhaps you want more
> control 

yes, more control

> 
> Which is where I can highly recc the use of jelly
> http://jakarta.apache.org/commons/jelly/

I will look into this.

> 
> I have found that there are some 'gotchas' with such dynamic
> instantiation and running of a build direct from ant api, though this
> could be down to my own limited knowledge.

Yes, I have seen some warnings on this. I was hoping there would be a 
way to do this with ant and still be safe. I will move this to the dev 
list and see if someone there can help.

best,
-Rob

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


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


RE: howto trigger an Ant build within java

Posted by Jim Fuller <ji...@ruminate.co.uk>.
> From: Robert Koberg [mailto:rob@koberg.com] 
> Sent: 29 January 2004 02:49
> To: user@ant.apache.org
> Subject: howto trigger an Ant build within java

> I am looking into using Ant (v1.6.0) more in my webapp so I can offer 
> offline publishing equivalents. I am transforming some config 
> XML into a 
> build file. I then want to load that build file into a new 
> org.apache.tools.ant.Project. The build.xml gets produce properly (it 
> runs successfully from the command line).

So the transformation of config file is happening in your app which
ultimately generates a build file, which in turn you would like to
simply run ant on ?

> How do I load the build file and create an ant project, then 
> trigger a 
> particular target to execute? The build file uses only Core 
> Tasks (and 
> an xmlcatalog). Is there a simple example somewhere? I have tried 

Hello Rob,

If you are physically generating the build file then just use the
launcher in the
http://nagoya.apache.org/gump/javadoc/ant/build/javadocs/index.html
org.apache.tools.ant.launch package. Though perhaps you want more
control 

Which is where I can highly recc the use of jelly
http://jakarta.apache.org/commons/jelly/

I have found that there are some 'gotchas' with such dynamic
instantiation and running of a build direct from ant api, though this
could be down to my own limited knowledge.

Cheers, Jim Fuller


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