aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Packaging applications with Ant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Packaging applications with Ant" Watch "Packaging applications with Ant" New topic
Author

Packaging applications with Ant

Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Hi,

I've become frustrated recently while trying to package EJB/WAR modules together in an EAR with Netbeans. I was wondering if using Ant would let me package applications without the use of an IDE??In this case, I'm trying to use local interface of a session bean but I don't know all the nuances to correctly use netbeans to set up dependancies etc between the modules....Maybe I should buy a copy of Ant in Action?


===>SCJP 1.5(72%)<===
==>SCWCD1.5(76%)<===
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Yes ANT (or Maven) can help you with this, I'd recommend looking through their documentation first, if that doesn't guide you well enough then yes the "ANT in Action" or "Maven the definitive guide" books are well worth reading.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Okay I'm convinced...thanks!
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

You're welcome!
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

Actually NetBeans project uses Ant, but the way it packages the EAR file is a bit ugly and it may not be compatible with other IDEs. I recommend that you give Maven a shot and NetBeans has made Maven as a first class citizen for the build tool.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16228
    
  21

Not only can Ant package applications, I have a strict policy that any project I do must be capable of being packages without installing and configuring/customizing an IDE. I got really burned by IDEs several years ago, and while I use them extensively, I'll never again let a GUI program be the final and only way to build a production software product.

Ant can literally package applications. Not just the Java components like WARs and EARs, but actual OS install packages, like RPMs and Solaris dpkg's, which can manage the external requirements like setting up work directories, customizing database connections and so forth.

All of which is equally true for Maven, incidentally.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
Tim Holloway wrote:...but actual OS install packages, like RPMs and Solaris dpkg's

... not to mention OS X disk images :-)


Ping & DNS - my free Android networking tools app
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

Hmmm....

Ant's not as easy as I thought.Maybe I'll put this on hold until after I finish SCBCD.
Arg....Ant,jQuery,Liferay there's still too much to learn!
Brendon Woodford
Ranch Hand

Joined: Jan 22, 2010
Posts: 53
I am using MyEclipse IDE and is new to ant. I am doing my project without the help of a build tool.
I am wondering whether I should use ant in building my project. And if I use ant what should my main build file contain and could anybody tell me how in real time a project building aspect is approached. What are the first considerations before deciding on the content of the build file.
My project encompasses servlet & JSP and using tomcat 5 server.

Thanks to all of you.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5842
    
    7

Wow, that is like asking for several years of experience of working with Ant to be summed up in a brief forum post. First, I recommend you do some reading - I highly recommend Ant in Action. I have an earlier addition of that book and I found it invaluable. Second, look at build scripts that others have done - I would offer the ones that I have for JBoss in Action, but they are a little complex for a beginner. Many open source projects use Ant build scripts (though many open osurcep rojects ar heading towards using Maven.) Finally, just play with Ant. Write lots of scripts. Between looking at other's scripts and writing your own you will develop a set of best practices that work for you. (I occasionally have the misfortune of having to look at some of my earlier build scripts, and shudder at some of the things I did in them, but hey, they worked!)


JBoss In Action
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5842
    
    7

I though about your question for a little longer, and noticed how you worded the question in your other post, and decided to offer some more concrete advice.

If you have to manually build a WAR file, what would you do? I talking about doing everything from the command line (well, except for editing the Java source files, you can use a text editor or IDE for that). I do hope that you have manually performed these tasks and not always relied on an IDE to do the work for you. Everyone should be forced to do things manually before being allowed near an IDE (but that is another topic entirely).

Anyway, the steps are pretty much this:
1) Compile the Java source code
2) Gather that files together than make up the WAR
3) Use the jar command to packages the files from step 2 into the WAR

You might want to consider prepending a step 0:
0) Set up your environment (i.e., identify the locations of your input and output files)

There you have the four targets that make up the build script. You will also want to add a fifth target, named 'clean', that removes the generated files. So you see, and Ant build script should reflect that setp you would have to do manually from the command line to accomplish your final goal.

I highly recommend that you spend a little time with Maven 2, even if you don't use it for building. Maven 2 has an assume directory layout that makes a lot of sense. Arranging your files in a well thought out and consistent layout and using that layout for all of your projects makes writing your Ant build scripts that much easier.
Brendon Woodford
Ranch Hand

Joined: Jan 22, 2010
Posts: 53
Peter Johnson wrote,
Wow, that is like asking for several years of experience of working with Ant to be summed up in a brief forum post. First, I recommend you do some reading - I highly recommend Ant in Action. I have an earlier addition of that book and I found it invaluable. Second, look at build scripts that others have done - I would offer the ones that I have for JBoss in Action, but they are a little complex for a beginner. Many open source projects use Ant build scripts (though many open osurcep rojects ar heading towards using Maven.) Finally, just play with Ant. Write lots of scripts. Between looking at other's scripts and writing your own you will develop a set of best practices that work for you. (I occasionally have the misfortune of having to look at some of my earlier build scripts, and shudder at some of the things I did in them, but hey, they worked!)



Thanks Peter for your suggestions.
It has been wonderful the way you considered my query. I will follow your advice and surely shoot back with some more queries. Hence forth I will continue with the same queries in the other post.webpage
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Packaging applications with Ant