• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

An ANT script [ build.xml] for ranchers

 
Bahadar Khan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

I am copying here an ant script that I use while studying HF book. It will make your work of building and deploying a WAR file in Tomcat container easy and save you a lots of time.

WHAT IT EXPECTS:

0: Create a main project directory say HFExample
1: Put your *.java source file in under HFExample/src
2: Put your html, jsp files uder HFExample/jsp
3: Put your web.xml file under HFExample/conf
4: Copy this ( build.xml ) under root HFExample
5: Type under your project root directory :/HFExample/ANT [Press ENTER}

WHAT IT DOES:

*It will create necessary directory structure
* Copy the files under proper web application structure
* Make a project_name.war ( in this case HFExample.war )
* deploy your application in the Tomcat


*** You can use this script in your subsequent projects, just change the project name and its location each time you want to use it in new projects by changing name in line 2 & 3.*****

<project default="init">


<property name="app.name" value="HF8"/>
<property name="web.app" location="./HF8"/>
<property name="src.dir" location="./src"/>
<property name="bin.dir" location="${web.app}/WEB-INF/classes"/>
<property name="server.dir" location="E:\Tomcat\jakarta-tomcat-5.0.28\webapps"/>
<property name="conf.dir" location="./conf"/>
<property name="html.dir" location="./jsp"/>

<property name="app.dos.name" location="${server.dir}/${app.name}"/>

<!-- Make Necessary Directories -->

<target name="make_dir">
<mkdir dir="${web.app}"/>
<mkdir dir="${bin.dir}"/>
</target>



<!-- Compilation -->

<target name="compile" depends="make_dir">
<javac srcdir="${src.dir}" destdir="${bin.dir}"/>
</target>



<!-- Make Web Application -->

<target name="assemble" depends="compile">
<copy file="${conf.dir}/web.xml" todir="${web.app}/WEB-INF"/>
<copy todir="${web.app}">
<fileset dir="${html.dir}"/>
</copy>
</target>



<!-- Make War File -->

<target name="jarup" depends="assemble">
<delete file="${web.app}.war"/>
<jar destfile="${web.app}.war" basedir="${web.app}" includes="**/*.*"/>
</target>





<!-- Deploy To Server -->

<target name="deploy" depends="jarup">
<delete file="${server.dir}/${app.name}.war"/>
<delete dir="${app.dos.name}"/>
<copy file="${web.app}.war" todir="${server.dir}"/>
</target>


<target name="init" depends="deploy"/>


</project>


cheers

-Bahadar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic