Thursday, August 11, 2011

Different ways to perform Sample URL handler Mapping in Spring

Normally the SimpleUrlHandlerMapping is done inside the xxx-servlet.xml file that is inside the WEB-INF directory of your Spring project. There are different ways to do this and two ways can be described as below.


Method 1

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<property name="alwaysUseFullPath" value="true"/>

Method 2

<bean id="sampleMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<prop key ="/account/register.jsp">
<property name="alwaysUseFullPath" value="true"/>

flowController is an another bean id and that bean is refered whenever the relevant URL request comes.

Chathuranga Tennakoon

How to create web application project using maven

today i decided to post how to create new web application project using maven. the following command should be typed in your linux vi editor for creating new project with maven. In linux terminal, go inside your project directory where the project source files should be created.then invoke the following command in the VI editor to create new project.

mvn archetype:generate -DgroupId=org.convery.example -DartifactId=SpringEmailInGmail  -DarchetypeArtifactId=maven-archetype-webapp -Dversion=1.0

the most importnat parameter can be described as belows.

-DgroupId this reffers to the Packaging path
-DartifactId this refes to the project id

once this command is executed, it will take few times to create new project. once the project is created you can see the newly created project structure as follows.

SpringEmailInGmail (as we have specified for the project name)
|------ pom.xml

hope this will helpful for you..

Chathuranga Tennakoon

Ant script for j2me projects

<?xml version="1.0" encoding="UTF-8"?>

<project name="Test Runner" default="build">

<property name="wtk.home" value="C:/WTK2.5.2_01"/>
<property name="polish.home" location="C:/Program Files/J2ME-Polish" />
<property name="polish.vendor" value="chathuranga"/>
<property name="" value="pibt"/>
<property name="resource" value="C:/Documents and Settings/Administrator/scm/AbansSCM/resources"/>
<property name="polish.MenuBar.useExtendedMenuBar" value="true" />
<taskdef name="j2mepolish"


<target name="build">


name="Test Runner"
description="my final year project for Bsc degree in computing "
<requirement name="Identifier" value="Generic/AnyPhone"/>

<build resDir="${resource}"


<midlet class="MenuMidlet" name="Test Runner"/>



<target name="clean" >
<delete dir="build"/>
<delete file="${polish.vendor}-${}-example.jar"/>
<delete file="${polish.vendor}-${}-example.jad"/>
<delete file="${polish.jarName}"/>


<target name="rebuild" depends ="clean,build">

<target name="run">
<exec executable="${wtk.home}/bin/emulator">
<arg line="-Xdescriptor:dist/${polish.vendor}-${}-example.jad"/>


Monday, August 8, 2011

Apache Ant for building and Deploying Java Web Applications

 The following Ant Script can be used to build your web application and deploy it in the remote server. it is required to change the value of the properties based on their actual paths available in your server and development environment. the following Ant Script should be copied to the build.xml file that is available inside the root of your java web project directory. (if there is no build.xml file, you can just create it and copy the below codes to there )

<project name="myproject" default="all">

    <target name="init">
        <property name="server_home" value="C:/Program Files/Apache Software Foundation/Tomcat 6.0"/>
        <property name="server_deploy" value="${server_home}/webapps"/>
        <property name="servlet_jar" value="${server_home}/lib/javax.servlet.jar"/>
        <property name="outdir" value="./output"/>
        <property name="classes" value="${outdir}/webclasses"/>
        <property name="lib" value="${outdir}/lib"/>
        <property name="project_name" value="jdbc"/>

    <target name="prepare" depends="init">
        <mkdir dir="${outdir}"/>
        <mkdir dir="${classes}"/>
        <mkdir dir="${lib}"/>

    <target name="compile" depends="prepare">
        <javac srcdir="./src" destdir="${classes}">
                <pathelement location="${servlet_jar}"/>

    <target name="package" depends="compile">
        <jar destfile="${lib}/lib.jar" basedir="${classes}" includes="**/data/*.*"/>
        <war destfile="${outdir}/${project_name}.war" webxml="./WebContent/WEB-INF/web.xml">
            <fileset dir="./WebContent"/>
            <classes dir="${classes}">
            <lib dir="${lib}"/>

    <target name="deploy" depends="package">
        <copy file="${outdir}/${project_name}.war" todir="${server_deploy}"/>

    <target name="clean" depends="init">
        <delete dir="${outdir}"/>
        <delete file="${server_deploy}/${project_name}.war"/>

    <target name="all" depends="clean, deploy">



Solving Package javax.servlet does not exist Error using Eclipse and Ant

Suppose you are working on a web application project with Eclipse IDE, Apache ant and Tomcat server. When you compile and run the program you will get the following error saying that Servlet.jar API cannot be found.

Package  javax.servlet  does not exist

This error will get even if the servlet.jar API is available in the lib directory of the Tomcat web container. The reason for this error is you have not set the CLASSPATH environmental variable for referring javax.servlet API. In addition you have not set the Apache Ant run time class path to javax.servlet API.
You can follow the instructions given below to set both the classpaths properly.

1. Setting up CLASSPATH environmental variable.

 Right Click on My Computer -> Properties -> Advanced tab -> Environment Variables
(In that you can amend/create CLASSPATH environment variable to servlet.jar
(In my case, CLASSPATH=C:/Program Files/Apache Software Foundation/Tomcat 6.0/lib/javax.servlet.jar )

2. Setting up Apache Ant runtime classpath

In addition, it is required to include the javax.servlet API (servlet.jar ) into the Apache Ant runtime. This can be done using your Eclipse IDE as follows.
Click on Window menu -> preferences -> Ant -> Runtime -> Global Entries
(In this location, you can add the servlet.jar API to the Apache Ant runtime as an external JAR file).

if you follow the above instructions properly,  you should be able to compile and deploy your web application without having such compilation error.