The quickest way to setup SiteMesh is to import sitemesh-blank.war into your development environment or server.
Having said that, manually setting up SiteMesh is also a very straightforward process. These steps are also useful for setting up SiteMesh on an existing Web Application.
If you are using technology older than 2009 you should verify that your environment meets the SiteMesh requirements.
If you are a complete newbie to Java Web Application Development you should here is list of topics that you might want to Google before starting,
- What is an Java Application Server
- How to Setup the Eclipse with Tomcat
- How to Setup a Default Web Application
This tutorial teaches you how to set up SiteMesh within a Java Web Development Environment and should take about 5 minutes or less.
Shortcut: Don't have a development environment handy or know how to set one up? Download the "no install" SiteMesh Starter Kit which complets the steps below and skip straight to Start Using SiteMesh in 10 Minutes.
Setup Web Application
If you are new to JEE development and plan to follow along with the Start Using SiteMesh in 10 Minutes tutorial, use the context root of cafe.
Install SiteMesh Manually
Manually installing Installing SiteMesh into your web application consists of three steps,
- Add the SiteMesh library file to WEB-INF/lib
- Add the SiteMesh filter to web.xml
- Create a blank decorators.xml file
Setup Library File
Copy the SiteMesh jar file into your web application's WEB-INF/lib directory. In this example we downloaded SiteMesh 2.4.1 which uses the jar name, sitemesh-2.4.1.jar.
Add SiteMesh Filter
Add the following to WEB-INF/web.xml within the <web-app> tag,
<filter> <filter-name>sitemesh</filter-name> <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> </filter> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
Here is a sample web.xml,
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>mirabeau</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>sitemesh</filter-name> <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> </filter> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
Add Decorator Controller File
Create the a decorators.xml file in your WEB-INF directory,
<?xml version="1.0" encoding="UTF-8"?> <decorators> </decorators>
You IDE (Integrated Development Environment) may give you the warning, "No grammar constraints (DTD or XML schema) detected for the document."
This is just a warning (happens with many other xml files) and you can ignore it or disable the warning in your IDE.
If you start up your application server (container) and get no errors then SiteMesh is is ready to go. However, SiteMesh will not do anything yet. Continue to Start Using SiteMesh in 10 minutesMinutes.