Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Apache Ant APIs in Java program to programmatically build source files

I am looking for good and practical resources that will help me use the Ant APIs effectively. The project website just gives the documentation of the API which is not useful at all. Very few websites seem to give very brief tutorials on the subject.

Is there some resource I am missing out on? How can I use the Ant APIs for simple tasks, without spending hours browsing through them and looking at source code?

Thanks.

(Answers to previously asked questions not helpful - How can i use Apache ANT Programmatically )

like image 236
Shailesh Tainwala Avatar asked Apr 11 '11 08:04

Shailesh Tainwala


People also ask

How do I build an Ant build xml?

Create Ant build fileIn the Project tool window, select the directory, where the build file should be created. Right-click the directory and from the context menu, select New | File ( Alt+Insert ). In the New File dialog, specify the name of the new file with the xml extension, for example, build. xml.

Is Ant a Java build tool?

Apache ANT is a Java based build tool from Apache Software Foundation. Apache ANT's build files are written in XML and they take advantage of being open standard, portable and easy to understand.


2 Answers

As it turns out, the lack of good resources on using the Ant API, is known and intended. The bottom paragraph of this article from the Ant says -

The question you are probably asking yourself at this point is: How would I know which classes and methods have to be called in order to set up a dummy Project and Target? The answer is: you don't. Ultimately, you have to be willing to get your feet wet and read the source code. The above example is merely designed to whet your appetite and get you started. Go for it!

So this seems to be the only way to make best use of the API.

like image 174
Shailesh Tainwala Avatar answered Oct 01 '22 16:10

Shailesh Tainwala


..Java program to programmatically build source files

If compiling/Jarring is all you need and you can run it in an SDK (as opposed to a plain JRE), look to the JavaCompiler class for compilation. Then use the Jar related classes to build the Jars.

All J2SE. Ant not included, Ant not required.

like image 32
Andrew Thompson Avatar answered Oct 01 '22 16:10

Andrew Thompson