File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes How to call a build.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to call a build.xml" Watch "How to call a build.xml" New topic
Author

How to call a build.xml

Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Hi

How to to call or execute a build.xml (ant file) from a simple java program.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
java.lang.Runtime
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

You use the Ant.class from the Ant API and load your build.xml using the setAntFile(String fileName) and then use .execute();
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
This is not working...

Tom Johnson
Ranch Hand

Joined: May 11, 2005
Posts: 142
Is the file in the appropriate place? From the Ant docs:
public void setAntfile(java.lang.String s)
The build file to use. Defaults to "build.xml". This file is expected to be a filename relative to the dir attribute given.


You can use the following method to set the directory:

public void setDir(java.io.File d)

The directory to use as a base directory for the new Ant project. Defaults to the current project's basedir, unless inheritall has been set to false, in which case it doesn't have a default value. This will override the basedir setting of the called project.


HTH
[ December 05, 2008: Message edited by: Tom Johnson ]

<a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">Use Code Tags!!</a>
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Originally posted by Meet Gaurav:
This is not working...



Hey... I pointed you in the right direction... not giving you the whole answer...

Yes, you have to set the running directory with obj.setDir("dir-path");
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39396
    
  28
Not a beginner's topic. Moving thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to call a build.xml