Vaadin applications are deployed as Java web applications. A Java "web application" can contain a number of servlets, each of which can be a Vaadin application or some other servlet, and static resources such as HTML files. Such a web application is normally packaged as WAR (Web application ARchive) file, which can be deployed to a Java application server (or a servlet container to be exact).

For a detailed tutorial on how web applications are packaged, please refer to any Java book that discusses Java Servlets. Sun has an excellent reference online at http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/WCC3.html .

Remember that, in the Java Servlet parlance, "web application" means a collection of Java servlets or portlets, JSP and static HTML pages, and various other resources that form an application. Such a Java web application is typically packaged as a WAR package for deployment. Vaadin applications, on the other hand, run as servlets within such a Java web application. There exists also other kinds of web applications. To avoid confusion with the general meaning of "web application", we often refer to Java web application as "WAR" in this book.

The following files are required in a web application in order to run it.

Web application organization

WEB-INF/web.xml

This is the standard web application descriptor that defines how the application is organized. You can refer to any Java book about the contents of this file. Also see an example in Example 4.1, “web.xml”.

WEB-INF/lib/vaadin-6.x.x.jar

This is the Vaadin library. It is included in the product package in lib directory.

Your application classes

You must include your application classes either in a JAR file in WEB-INF/lib or as classes in WEB-INF/classes

Your own theme files (OPTIONAL)

If your application uses a special theme (look and feel), you must include it in VAADIN/themes/themename directory.

Widget sets (OPTIONAL)

If your application uses a project-specific widget set, it must be compiled in the VAADIN/widgetset/ directory.

The deployment descriptor is an XML file with the name web.xml in the WEB-INF directory of a web application. It is a standard component in Java EE describing how a web application should be deployed. The structure of the deployment descriptor is illustrated by the following example. You simply deploy applications as servlets implemented by the special com.vaadin.terminal.gwt.server.ApplicationServlet wrapper class. The class of the actual application is specified by giving the application parameter with the name of the specific application class to the servlet. The servlet is then connected to a URL in a standard way for Java Servlets.


The descriptor defines a servlet with name myservlet. The servlet class, com.vaadin.terminal.gwt.server.ApplicationServlet, is provided by Vaadin framework and it should be the same for all Vaadin projects. The servlet takes the class name Calc of the user application class as a parameter, including the full package path to the class. If the class is in the default package the package path is obviously not used.

The url-pattern is defined above as /*. This matches to any URL under the project context. We defined above the project context as myproject so the application URL will be http://localhost:8080/myproject/. If the project were to have multiple applications or servlets, they would have to be given different names to distinguish them. For example, url-pattern /myapp/* would match a URL such as http://localhost:8080/myproject/myapp/. Notice that the slash and the asterisk must be included at the end of the pattern.

Notice also that if the URL pattern is other than root /* (such as /myapp/*), you will also need to make a servlet mapping to /VAADIN/* (unless you are serving it statically as noted below). For example:

    ...
    <servlet-mapping>
        <servlet-name>myservlet</servlet-name>
        <url-pattern>/myurl/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>myservlet</servlet-name>
        <url-pattern>/VAADIN/*</url-pattern>
    </servlet-mapping>

If you have multiple servlets, you should specify only one /VAADIN/* mapping . It doesn't matter which servlet you map the pattern to, as long as it is a Vaadin servlet.

You do not have to provide the above /VAADIN/* mapping if you serve both the widget sets and (custom and default) themes statically in the WebContent/VAADIN/ directory. The mapping simply allows serving them dynamically from the Vaadin JAR. Serving them statically is recommended for production environments as it is faster. If you serve the content from within the same web application, you may not have the root pattern /* for the Vaadin servlet, as then all the requests would be mapped to the servlet.