This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant vs Maven newbie question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Ant vs Maven newbie question" Watch "Ant vs Maven newbie question" New topic
Author

Ant vs Maven newbie question

Jim Akmer
Ranch Hand

Joined: Jul 06, 2010
Posts: 104
Hi, Sorry for the newbie question.
I don't know neither Ant nor Maven. My question is which of the two is better to spend time to learn and why?

Thanks!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I don't really know how to answer that--both are still used frequently, although some folks are switching to things like Gradle, Gant, Rant, Rake, etc.

Maven does more "out of the box". When it breaks, it breaks *spectacularly*. If you need to do something *not* in the Maven way, it can be a real pain. Real as in literal-my-brain-hurts. Ant requires more manual labor, but with things like Ivy (dependency management) can do "all" the things Maven does, but only with effort.

So it's up to you.
Jim Akmer
Ranch Hand

Joined: Jul 06, 2010
Posts: 104
Also if I use an IDE, why would I need to learn a build tool?
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Jim Akmer wrote:Also if I use an IDE, why would I need to learn a build tool?

An IDE is only for development - when you then need to deploy/distrubute whatever you have done - then you need to do some packaging, and it is here that ANT/Maven will/can be used.

If you need to e.g. generate Java Client Source Code from a web service (WSDL), then you can use Ant/Maven or a command line to do it - but to be able to re-use the command used more easily, it would be a good idea to use Ant or Maven where you then have it documented in their build scripts (some IDE's can also do this kind of code generation, but they normally use some kind of build tool behind the scene).
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15961
    
  19

Jim Akmer wrote:Also if I use an IDE, why would I need to learn a build tool?


There are a number of reasons.

1. While this isn't as big a problem in Java as on other platforms, changes in IDE versions can result in problems building applications down the road. A certain very large offender that I won't name was pushing it to the point where I think now some of my older apps would actually require re-installing an obsolete version of their OS in order to install an obsolete version of their IDE just to make an emergency 1-line code change. The batch builders such as Ant and Maven are less version-sensitive when it comes to backwards compatibility.

2. I worked in a shop where we were supposed to be sharing components. For the most part, we couldn't, because to build the components, you have to have precisely duplicated the IDE setup that the original author used, including his/her departmental standards and services. Which at best, was a major pain to set up, and at worst, conflicted with our own departmental IDE configurations.

3. I've also worked in environments where you submitted only source code for production. The actual binaries were produced elsewhere, thus ensuring both buildability and eliminating any hidden binary "back doors". However, the build process was done in batch on a server machine that had no GUI desktop, and therefore no IDE.

4. Very complex projects often require extra build steps such as rmic, xdoclet and so forth. Trying to setup an IDE to include all this is no trivial task. I generally don't even try, since it's easier to run Maven or Ant.

5. A particular virtue of Maven is that (like it or not), it enforces a standard project structure. Essentially, if you've seen one Maven project, you've seen them all. I don't claim I totally love its standard organization, nor for that matter, a number of other things about Maven. However, I know that if someone dumps a project on me, I won't have to waste time finding where everything is.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Plus a build file can be used by a CI (Continuous Integration) server. Plus you can customize the build at build time (similar to the point about additional tasks) like building only certain components, etc. without having to have an explicit target (Ant target, I mean) or change the build configuration--just by defining a property on the command line. Plus you can build on the command line more easily than with an IDE's embedded build process for quick changes without having to slog through IDE startup.

For small, personal, one-off projects, it may not matter. For real work, it does.
Jim Akmer
Ranch Hand

Joined: Jul 06, 2010
Posts: 104
Thank you all for the great answers!
One last thing though. Since I do not know neither Ant nor Maven, which will give me more of an advantage (more frequent wanted from companies, more frequently used by frameworks etc) to spend time learning?Also if learn one of these, is the learning of the other (if needed) trivial (the concepts are the same?) or it is like starting all over?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I have no idea which is used more. I have yet to work for a company that uses Maven, but I know of many companies that do.

It's like starting all over.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

You should learn a little about Maven even if you go with Ant. Maven very strongly recommends (i.e. dictates) a very specific directory structure and while I have a few nits with it, I always use that structure, or a slight modification of if, with any Ant-based projects that I have.

Be aware that Maven is a black-box. It is a whiz regarding build/test/packaging because that knowledge is built in. To get it to do anything other than what it was written to do (such as generate two artifacts for a single project) is often an exercise in frustration. Ant, on the other hand, is more of a scripting language - it gives you a lot of primitives that you can combine in interesting ways to do a variety of things, with build/test/packaging being only some of those things.

You should definitely read a book. Ant in Action is a must-have for Ant - I have the author's prior version of that book and found it indispensable. For maven, there are two good books online: Better Builds With Maven and Maven the Definitive Guide.


JBoss In Action
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ant vs Maven newbie question
 
Similar Threads
jdo and eclipse
Maven Vs Ant
ant or maven
Compile and deploy from DOS prompt
whats the diff. b/w ANT and MAVEN?