How to configure Eclipse, Tomact 5.5, velocity


It took me a whole day to get my head around the configuration of Tomcat with latest velocity package

So I thought why not i should share it with the world.

Tomcat 5.5
Velocity Tools
Sysdeo Tomcat launcher plugin
Lots of Patience


After downloading the above mentioned packages follow the below mentioned steps

Step 1: Setup Eclipse and Tomcat

Unzip the sysdeo plugin and copy it into plugin folder of the eclipse
Restart the Eclipse

Some new Menu button will be added in the Eclipse

  • Click on windows menu of Eclipse->Preference
  • Click on Tomcat on the left hand listbox
  • Click in Tomcat 5.X radio button
  • Browse the Tomcat home i.e where Tomcat is installed.
  • Select Context radio button in Context declaration mode (This will allow web application to declare resource in their own context.xml file)
  • Click Apply

Step 2 : Creating a Tomcat Project

Go to Menu of Eclipse follow the instructions below

File-->New-->Projects-->Tomcat Project

Due to the sysdeo plugin web directory structure with necessary jars will be creates

Step 3 : Setting up Velocity 1.6.x and Velocity Tools

  • Extract the downloaded velocity package in the folder you like
  • Right Click on Referenced Libraries in Eclipse
  • Click on Build Path-->Configure Build Path menu options
  • Click on External Jars button and add velocity-1.6.2, velocity-1.6.3-dep.jar, Velocity-tools-1.4.jar, Velocity-tools-view-1.4.jar

This will include the jars in build path of web application.

Step 4 : Writing some code

Create a any class under WEB-INF/src directory in eclipse
Below is the test class I have used

public class SimpleServlet
private String message = "Hello from ToyTool!";

public String getMessage()
return message+" "+foo;


public void setMessage(String m)
message = m;

/** To test exception handling in templates. */
public boolean whine() {
throw new IllegalArgumentException();


Step 5 : Setting up necessary xml files

There are three file web.xml, toolbox.xml, which are important at the moment.

Create three empty file name web.xml,, toolbox.xml under WEB-INF directory

Open web.xml

Copy and paste below code mentioned
<?xml version='1.0' encoding='utf-8'?>

<!-- Define Velocity template compiler -->

<servlet-class> </servlet-class>




<!-- Map *.vm files to Velocity -->


Open toolbox.xml

Copy and paste the code below mentioned
<?xml version="1.0"?>

<data type="number">
<data type="boolean">
<data type="string">
<value>this is foo.</value>
<data type="string">
<value>this is bar from velocity.</value>


Copy ans paste the code below mentioned



Create a folder name called "templates" under WEB-INF directory
template folder will contain all our velocity templates

Create a index.vm file under template directory which will serve as template for the respective servlet

Copy and paste the code in the index.vm

The Geek Head $serv.getMessage()

Step 6 : Testing the above configuration

Time to check weather velocity is configured properly
Click on Tomcat menu-->stat Tomcat
And test the following url http://localhost:8080/Tomcattest/index.vm
where the Tomcattest is the project name

For further documentations please visit respective package's website.


:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Post a Comment