aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Creating a build and deployable using 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 "Creating a build and deployable using Ant" Watch "Creating a build and deployable using Ant" New topic
Author

Creating a build and deployable using Ant

Priety Sharma
Ranch Hand

Joined: Jun 10, 2008
Posts: 156

Hi,

I have developed a small web application on Tomcat 5.
I want to build this application using ant.
I also want to create a deployable .war file using ant.

I have installed ant and done the path settings.

Now what do I write in the build.xml to create a build and deployable for this project.

I refered to some sample build.xml and also checked out its syntax but am still confused.

There have to be some targets to get this done is what I understand.

I am stuck there.

----------------------------------------------------------------------------------

Here is my project structure in Tomcat 5

I have a project called onlinelib inside the webapps directory.
In the onlinelib directory I have some jsp's.

In the WEB-INF\classes directory I have a servlet class called HelloWorldExample where I create a database connection to derby and all my jsp's action element point to this servlet.
So this acts like the controlling servlet.

In the WEB-INF\classes\jbean directory I have a java bean class called BookSelectedforDel.

-------------------------------------------------------------------------------------


Priety.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

When you are describing your project structure, is this the structure of your source code? Or the structure of the results after compiling? I hope that it is the latter. For example, it is not a good idea to place the .java source files in WEB-INF/classes, instead you should place them in another directory such as src/main/java, and resources (JSPs, html, css, etc) should go in src/main/webapp.

I recommend that you install Maven and study the project directory structure that it dictates. Even if you don't use Maven for builds, its directory structure is worth emulating with Ant. There are some good free online book on Maven:
http://www.topazproject.org/trac/attachment/wiki/MavenInfo/BetterBuildsWithMaven.pdf?format=raw
http://www.sonatype.com/books/maven-book/

Other than that, the typical steps are:
1) Compile the .java files (the .class files go into target/classes)
2) Gather the classes and resources into a central location (building and exploded WAR structure)
3) Packaging the WAR (from the directory built in step 2)

Google building war with ant will yield some examples, though some are overly complicated and many don't have the clean directory structure that Maven has.

Finally, use packages to separate your beans from your servlets.


JBoss In Action
Priety Sharma
Ranch Hand

Joined: Jun 10, 2008
Posts: 156

Hi Peter,

Thanks for giving such a descriptive reply.

I will make all the changes you have suggested.
I know that my directory structure looks haphazard.

Will let you know once I have done that and then will try to use ant to create a deployable.

Thanks a lot.

Hey, and thanks to you I came to know about Bumper Stickers. I have added a couple now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a build and deployable using Ant