Build and test application
Posted on: December 2, 2010 at 12:00 AM
In this tutorial you will learn how to build struts2.2.1 in ant and run it

Build and test application

Building and application using ant

At first download the Ant from the Apache site and then configure it in your system environment variable Now make a build.xml file as


<project name="Struts 2 Tutorial" basedir="../" default="all">

<!-- Project settings -->
<property name="project.jar.file" value="struts2tutorial.jar"/>

<path id="class.path">
<fileset dir="lib">
<include name="**/*.jar"/>
<fileset dir="libext">
<include name="**/*.jar"/>

<!-- Classpath for Project -->

<path id="compile.classpath">
<pathelement path ="lib/commons-beanutils.jar"/>
<pathelement path ="lib/commons-digester.jar"/>
<pathelement path ="lib/struts.jar"/>
<pathelement path ="libext/servlet-api.jar"/>
<pathelement path ="libext/catalina-ant.jar"/>
<pathelement path ="classes"/>
<pathelement path ="${classpath}"/>

<!-- Copy any resource or configuration files -->

<target name="resources">
<copy todir="src/classes" includeEmptyDirs="no">
<fileset dir="src/java">
<include name="**/*.conf"/>
<include name="**/*.properties"/>
<include name="**/*.xml"/>

<!-- Normal build of application -->
<target name="compile" depends="prepare,resources">
<javac srcdir="src" destdir="src/classes" debug="true" debuglevel="lines,vars,source">
<classpath refid="class.path"/>

<!-- Remove classes directory for clean build -->
<target name="clean"
description="Prepare for clean build">
<delete dir="src/classes"/>
<mkdir dir="src/classes"/>

<!-- Build entire project -->
<target name="project" depends="clean,prepare,compile"/>

<!-- Build project and create distribution-->
<target name="all" depends="project"/>


In the above file you set the library, source directory, destination directory, pattern set, etc.

Save this build.xml file in the source directory. Now open the command prompt and go to the source directory and then type ant and press enter then the console appears like this

This indicates that you have built the project successfully. Now start the tomcat and open the browser ant type http://localhost:8080/login/roseindia/loginPage.action

Then the page appears like this.

Login Page

Home Page

If you give password other than "web" The control remain on the login page

Download this example code

Related Tags for Build and test application:



Advertisement null