Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a build and deployable using Ant

 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

-------------------------------------------------------------------------------------
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic