views:

1271

answers:

12

I see reference of ant a lot but I don't get exactly what its meant to do? from what i've heard its supposed to compile your projects but can't i just do that by clicking Run->Run in eclipse?

Edit : I guess I should rephrase my question. I already know that ant is a 'build automation software', my question is, what exactly is build automation? I thought that you're supposed to test your app, and when it is running you click the 'build' button in eclipse or through command-line java, and it makes a .jar file out of it? So why do you need to 'automate' this process?

+6  A: 

Ant is for automating software build processes:

http://en.wikipedia.org/wiki/Apache_Ant

rogeriopvl
I hate it when someone posts a link on wikipedia to an answer. Don't you think i would've checked that already before i posted here?
Click Upvote
@Click: Not necessarily - there certainly wasn't evidence of that in your original question. The answer to the question as per the title is "to automate build processes". Given that "clicking a button" *isn't* automation, I fail to see in what way this answer is bad at all.
Jon Skeet
@Click Upvote: Small surprise, but I agree with @Jon Skeet; your question was flawed and showed every indication that you didn't do even basic research on the subject. @regoeriopvl certainly doesn't deserve an offensive flag for his succinct and accurate reply.
Randolpho
@ClickUpvote: don't be rude. If you ask a question, this means that the information you have is not enough. How should one know what your base knowledge is. If you have read http://www.catb.org/~esr/faqs/smart-questions.html, you should have known to put what you tried in the question.
Sunny
I've rephrased my question to better explain what I wanted to know.
Click Upvote
@Jon Skeet, if you read the body of the question again I've specifically said that i've heard of ant a lot but I don't *get* what exactly it means. If you then answer with something that i've already heard 500 times without knowing what it means, to me that's offensive
Click Upvote
@Click: You said you'd "see[n] reference of Ant a lot" which isn't the same thing as knowing that it's a build automation tool. You said you knew it compiled a project, but there's more to building than compiling. If you don't explain your question well enough, that's your fault, not responders'.
Jon Skeet
In particular, if you had read the Wikipedia article in its totality, you'd have a heck of a lot better idea what it's about than your question implied.
Jon Skeet
I agree with Click Upvote here, the Wikipedia entry is not very clear if you don't already know what it is. Look at the opening paragraph; there's no real info there except a comparison to 'make'. Now, a link to wikipedia's "Build Automation" entry actually IS helpful.
Outlaw Programmer
Which is also the first reference under "See Also"... not exactly hard to find if you're really interested.
Jon Skeet
A: 

Eclipse is using ant for building, running, deploying, ...

"Ant is a Java-based build tool. In theory, it is kind of like Make, without Make's wrinkles and with the full portability of pure Java code." (from link text

Dutow
Eclipse doesn't use ant for most tasks. Netbeans is the one that uses ant for everything.
Joachim Sauer
+12  A: 

rogeriopvl is absolutely correct, but to answer your "can't I just do that by clicking Run->Run in Eclipse?" question: that's fine for a project that you're working on on your own, and don't need a repeatable, scriptable build in multiple environments.

If you're working on an open source project, however, or professional software which needs to be able to build on a build server etc, requiring a particular IDE to be running isn't a good idea.

Jon Skeet
Expanding on that a bit. Unless you're a single developer, building the "production" build in your IDE is a bad idea. Someone on a different system may have different PATHs, jars, versions, etc. Ant provides a system independent build, often including stuff like unit tests, source labelling, etc.
Chris Kessel
+2  A: 

Ant is a build tool, akin to makefiles (albeit with a very different syntax in XML). If you're only using Eclipse it's fine to stick to that and you can always convert an Ant build file into an Eclipse project (Eclipse's launch configurations are then, if I remember correctly, the equivalent of Ant's build targets).

If you want to deploy the source code of the application and allow others to easily build or set it up, automating that using Ant is probably not a bad idea. But it's usually not a consistent experience for users or at least I haven't seen much consensus on what targets should be there and doing what so far.

Ant may also be used for regular automated builds (you wouldn't want to hit Run in Eclipse every night, right? :-))

Joey
A: 

You are also referring to the ""Export ant buildfile".

If you write your own Ant script for building your application outside eclipse, you can write your own targets that use the Ant task to delegate to the generated build.xml.

Also, you can configure a project's 'builders' (project properties » Builders) to run any script (ant or otherwise) you want when you build the project, manually or automatically.

VonC
+4  A: 

Ant allows CRISP (complete, repeatable, informative, schedulable, portable) builds. You can find great info on it in this presentation by Mike Clark and in his book, Pragmatic Project Automation.

Fabian Steeg
+4  A: 

In many larger companies (and likely some smaller ones), you'll find that production code is not built by the people who developed it. Instead, the developers may check their code into a source code repository and tag it. Then they give this tag to a build team.

The build team, in a separate (clean) area - possibly on some headless server (i.e. with no GUI) - will then check out the code and run a build script. The build script will be completely independent of the desktop environment/IDE.

This ensures that nothing which happens to be on any one developer's computer is "polluting" the build. (Or, more likely, nothing outside source control is required for the system to work!)

So most software you use will never, ever be built from a developer's desktop.

PS. You might also want to look at the idea of Continuous Integration

oxbow_lakes
+3  A: 

The short answer is that Ant is a great way to create a complete project build that is independent of any particular tool any developer may be using. Without an independent build, things can go haywire quickly - especially for large project teams.

And now for the long answer... I have been brought into several projects without any sense of an independent build. On one project, there was one guy who was not a developer that was tasked with building and deploying the software. He had created 147 separate windows batch files to compile each EJB, each servlet, and each client component. There was no error checking for this build. All log messages, including error messages went to standard out. It was up to him to manually recognize by reading this log which exception or message printed was a normal and which message was an error. He also had to deploy this software he just built. Deploying was equally as complex since there were several load-balanced tiers. Each module had to be placed in the right place manually with options setup to match downstream and upstream tiers. Building and deploying this software took him at least 3 days using this method. Of course, only then could anyone determine if the build "worked". Usually, after this period all the programmers would scramble to debug the build. Programmers would say my module works fine in my IDE. I just click run like this, see?

Indeed, the individual software modules usually worked, but the build and deployment was horribly ineffective. And just as bad, it was equally as difficult for anyone to deploy a build to more than one environment. Management would say, ok you now have this build working in our regression testing environment. Now deploy that same build in this other environment so the sales guys can demo up and coming software. That should be simple to do, but it also took at least 2 days, followed by a "debugging the build" period. Builds and deploys were never simple and never accurate. It really slowed the project down.

Anyway, we replaced this entire procedure with a complete Ant based build and deploy mechanism. The end result was that a complete build could be created and deployed in less than 30 minutes, completely automated. The QA guy managing the builds and deploys could keep a whiteboard of which environment had which build deployed to it and which group was using that environment. This was something that was just not possible with the old system.

Gary
+6  A: 

Ant is used to automate a build process, but a build process is often much more than compiling. Ant has "tasks" that can be used to perform miscellaneous useful functions. You can create your own task to do just about anything by writing a java class and telling ant where to find it. You can then mix and match these tasks to create targets that will execute a set of tasks.

You can also set up a dynamic environment in which to build your application. You can set up property files to hold variables that can be used in the build process, i.e. to hold file paths, class paths, etc. This is useful for instance to differentiate between test and production builds where deployment paths, database instances, etc. might change. Ant also includes flow control (if, etc.)

Some things I've seen ant do:

  • Compile code
  • Use version control to checkout the latest version or to tag the version being built
  • Run sql scripts to build or rebuild a test database
  • Copy files from an external resource for inclusion in a project
  • Bundle code into a jar, war or ear file
  • Deploy a web application to an application server
  • Restart an application server
  • Execute a test suite
  • Static analysis, i.e. CheckStyle or PMD
  • Send email to a team to alert them to a build.
  • Generate files based on information from the build.
    • Example: I have a jsp in my app that does nothing but display version/build information. It is generated by ant when I run a build, and the production operations team checks this page when they deploy the application to make sure they've deployed the correct build.
mtruesdell
+1  A: 

If there's one close to you I think you'd get a lot out of CITCON, the Continuous Integration and Testing Conference. You get to talk with lots of people about the benefits of automation applied to building and testing software.

Basically people use Ant (with other tools) to automate everything they want to have happen after a commit. The basic advantages of such automation are faster, better and cheaper.

Faster because things happen right away without waiting for a human to get around to it.

Better because computers are really really good at doing the same thing the same way every time. (Humans tend to suck at that.)

Cheaper because you have fewer mistake and the mistakes that occur are caught sooner and therefore cheaper to fix.

Jeffrey Fredrick
A: 

Joel (Spolsky) has a great article on "The Joel Test." Many of them revolve around being able to do important things often, quickly and reliably. One of those things is your build.

Jared
+7  A: 

I already know that ant is a 'build automation software', my question is, what exactly is build automation? I thought that you're supposed to test your app, and when it is running you click the 'build' button in eclipse or through command-line java, and it makes a .jar file out of it? So why do you need to 'automate' this process?

Not all the Java development is done through eclipse and not all the jars may be built from the command line ( or should be built from the command line ) .

You may need additionally run test cases, unit tests, and many, many other process.

What ant does, is provide a mechanism to automate all this work ( so you don't have to do it every time ) and perhaps you may invoke this ant script each day at 6 p.m.

For instance, in some projects, a daily build is needed, the following are the task that may be automated with ant, so they can run without human intervention.

  • Connect to subversion server.
  • Download/update with the latest version
  • Compile the application
  • Run the test cases
  • Pack the application ( in jar, war, ear, or whatever )
  • Commit this build binaries to subversion.
  • Install the application in a remote server
  • Restart the server
  • Send an email with the summary of the job.

Of course for other projects this is overkill, but for some others is very helpful.

OscarRyz