File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant build process - when does compilation actually happen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Ant build process - when does compilation actually happen" Watch "Ant build process - when does compilation actually happen" New topic

Ant build process - when does compilation actually happen

Chris Cassano

Joined: Jun 20, 2012
Posts: 2
Hi, I've got a project that I'm trying to deploy and I'm having some issues. My question is when does compilation happen in the build.xml file? My ant build is finishing successfully but there are no files in my projecthome/bin folder. I know that when the build process finishes, there should be class files in the bin folder. What directive in the build.xml file tells ant to compile? How can I make ant create the .class files? I don't think that I have to call <javac> explicitly, right? Ant should generate the class files on it's own, or am I wrong?

If I'm misunderstanding something then please explain how it works. I'm new to Ant and I'm trying to build someone else's project.

Thanks in advance.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32023

You do have to call <javac> explicitly. Ant doesn't do things unless you tell it to. (unlike Maven which compiles by default.)

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16725

Ant build files are basically "programs" and they build things under specified orders. If you don't specify a task, it doesn't get done. An empty build.xml does nothing at all.

Maven POMs are information repositories. Maven builds everything by "magic", using the POM as a reference and inferring lots of things if they aren't explicitly defined in the POM.

Since I'm not a big fan of "magic", I resisted using Maven for a long time, but these days I use it more than I do Ant.

Customer surveys are for companies who didn't pay proper attention to begin with.
Peter Johnson

Joined: May 14, 2008
Posts: 5850

Ant is a scripting language, much akin to the make tool for C/C++ development. Only the operations defined in the script will be performed. Gives you lots of power: you can do pretty much anything you want, and that is not restricted to just building Java apps. But you do have to tell it exactly what you want done.

If you want things to be done automatically based on best practices, then use Maven. It will compile your sources, run your unit tests, package up the JAR file, and even generate a number of reports, without you having to do anything other than give it some basic information about your project (mainly what you want to name it).

JBoss In Action
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16725

Technically, it's not scripting, which is why I said "programs" in quotes. Ant build.xml files (and Unix makefiles) are declarative files, not executables (scripts). But pedantry aside, the net effect is the same. Ant will only perform tasks which have been explicitly requested.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Ant build process - when does compilation actually happen