This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion 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: 33132

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]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

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.

An IDE is no substitute for an Intelligent Developer.
Peter Johnson

Joined: May 14, 2008
Posts: 5852

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: 17421

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.
I agree. Here's the link:
subject: Ant build process - when does compilation actually happen
It's not a secret anymore!