• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Packaging applications with Ant

 
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay I'm convinced...thanks!
 
Martijn Verburg
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome!
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:...but actual OS install packages, like RPMs and Solaris dpkg's


... not to mention OS X disk images :-)
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!)
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
reply
    Bookmark Topic Watch Topic
  • New Topic