While more and more server based frameworks,
libraries, standards, and architectures for Java are
invented to make programmer's life easier, software
deployment seems to get harder and harder. For
example, Java Enterprise Beans tried to make creation
of persistent and networked objects easy and somewhat
automatic, but the number of deployment descriptions
got enormous. As IT Mill Toolkit lives in a Java
Servlet container, it must follow the rules, but it
tries to avoid adding extra complexity.
All IT Mill Toolkit applications are deployed as Java web
applications, which can be packaged as WAR files. For a detailed
tutorial on how web applications are packaged, we refer to any Java
book that discusses Servlets. Sun has excellent reference online on
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/WCC3.html
.
Creating Deployable WAR in Eclipse
To deploy the created application to a web server, you need to
create a WAR package. Here we give the instructions for Eclipse.
Open project properties and first set the name and destination of
the WAR file in Tomcat tab. Exporting to WAR is done by selecting
from in project context menu (just click calc
with right mouse button on .
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 3.1, “web.xml”.
-
WEB-INF/lib/itmill-toolkit-5.0.0.jar
-
This is the IT Mill Toolkit 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
WEB-INF/lib/themes/themename
directory.
Deployment Descriptor web.xml
The deployment descriptor is an XML file with name
web.xml in WEB-INF directory of
a web application. It is a standard component in Java EE that describes
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.itmill.toolkit.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.
Example 3.1. web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>com.itmill.toolkit.terminal.gwt.server.ApplicationSer
vlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>MyApplicationClass</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
For a complete example on how to deploy applications, see
demo/itmill-toolkit.war that includes demo
applications. You can simply deploy this web application to your
favorite application server by server specific means. For
example, in Apache
Tomcat you simply copy the WAR file to the
webapps directory.
If you wish to examine the contents of the WAR
file, you can decompress it using a standard ZIP
or JAR decompressor. For some ZIP implementations,
you must rename the file to
itmill-toolkit.zip .
Deployment descriptor can have many parameters and options that
control the execution of a servlet. You can find a complete
documentation of the deployment descriptor in Java Servlet
Specification at
http://java.sun.com/products/servlet/.
One often needed option is the session timeout. Different servlet
containers use varying defaults for timeouts, such as 30 minutes
for Apache Tomcat. You can set the timeout with:
<session-config>
<session-timeout>30</session-timeout>
</session-config>
After the timeout expires, the close()
method of the Application class will be
called. You should implement it if you wish to handle timeout
situations.