EQUIP2 WebApp: Deploying
Chris Greenhalgh, 2007-01-29; last update 2007-10-25
Introduction
This document gives information about deploying an EQUIP2-based Web
application. Specific information is given for using Apache Tomcat and
Jetty as the the target J2EE Servlet
container, but others should also work (as long as they support Servlet
2.4 specification).
Before deployment, the web application must be configured and built:
see EQUIP2_WebApp_Configuring_and_Building.html.
Installing the Servlet container
Tomcat
You will require at least Tomcat version 5.5, e.g. Tomcat 5.5.16.
Tomcat is commonly used for production services, often behind an Apache
web server.
Tomcat is
normally a standalone installation, which runs continually in the
background as a service (Windows) or daemon (*nix). See Tomcat's own
documentation.
Jetty
Jetty is a pure Java Servlet
container
which can be run as a service but is more often used as a standalone or
embedded container. Current version is (was) 6.1.6, available from http://dist.codehaus.org/jetty/
(rather than the old sourceforge project). By default, run Jetty from a
command console in its
top-level directory using:
> java -jar start.jar
Running the start.jar directly may have the same result
(although the console may not be visible).
Note: I am currently unsure if behaviour under Jetty differs in key
ways from Tomcat.
- The tutorial application does a redirect from a JSP view which
does its redirect relative to the internal URI of the JSP, not the
original request URI. Is this correct? consistent? (my Tomcat
installation is not working at the moment)
- I had to remove the jstl.jar & standard.jar from the
deployment, relying on the ones in the webapp or the jstl forTokens
example failed. Again, not sure if this is different to Tomcat.
Other containers
Consule the container's own documentation for installation guidance.
Deploying
Database
If you are using the default HSQLDB in-process database then you
don't need to do anything to set up the database.
NOTE:
there was an issue with the previous IDAllocator, which
relied on functions and did not work
with HSQLDB. The latest IDAllocator should correctly fall back to
operating without function(s).
Otherwise, you will need to create the application's back-end
database before
deploying the application. The details must match the configuration
provided in etc/hibernate.cfg.xml.
For example, if you are using mySQL (and have changed the Hibernate
configuration accordingly) for the default
database name/user name/password for the minimal application you can
use the mySQL console client to do:
> create database equip2minimal character set utf8 collate utf8_bin;
> grant all on equip2minimal.* to equip2minimal@localhost identified by 'equip2minimalpw';
> flush privileges;
You will
require suitable database access rights to do this.
Web application
Deploying an EQUIP2 web application is basically the same as
deploying any other Java Servlet-based application.
The web build/deploy process is supported by the following ant build
targets:
- ant war - compile
the complete web application to a Web ARchive file, dist/equip2minimalwebapp.war
[or whatever you have changed the web application name to in build.xml] file
ready for deployment.
- Either:
- Copy the created WAR file directly into the target J2EE servlet
container's webapps directory
- Tomcat on windows,
this is typically C:\Program
Files\Apache Software Foundation\Tomcat 5.5\webapps
- Jetty, this is typically the webapps subdirectly of the
jetty installation directory.
- the
warfile will normally then be unpacked into a equip2minimalwebapp [or
whatever] directory
- Or:
- (having set tomcathome
in build.properties) do "ant deploy" which will copy the
web app files directly to the target container's webapps
directory (assuming it is on the local machine).
- Or for Tomcat:
- Open a web-browser to view the Tomcat manager page, http://localhost:8080/manager/html
(assuming it is running on the local host and port 8080; you will need
the Tomcat admin username and password to access this page).
- Use the WAR file to deploy option to upload and deploy the equip2minimalwebapp.war
warfile. If successful /equip2minimalwebapp
should now be listed in
the
Applications list.
See below for Checking
If you make changes then doing "ant
deploy" again should copy only
the changed files into the
target container. In
some
cases these will be picked up right away (e.g. new HTML or JSP files,
probably new but not changed java class files and new additional
libraries).
Updating on Tomcat
However in
some cases you will need to at least reload the application (use the
Tomcat manager), e.g. if you change the web.xml or Spring configuration
files.
If you do not have direct access to the Tomcat directory, or if you
make a major change and reloading doesn't seem to work then you will
need to undeploy
the old version (in the Tomcat manager) before deploying the new
version (as above).
If undeploy fails then you may need to stop tomcat, delete the
web application directory from Tomcat's webapps directory, and restart
tomcat.
If deploy fails then you will need to check the Tomcat logs,
normally under .../Tomcat
5.5/logs, in particular localhost.<DATE>.log
(and any other recently modified files). On windows you may need to
open them with notepad rather than wordpad if Tomcat is still running
because of file locking issues.
After 10 or so re-deploys/reloads I tend to get an out of memory
error ("PermGen"); this seems to be a known issue and requires a
restart of Tomcat.
Updating on Jetty
For general changes terminate Jetty (e.g. CTRL-C in its console window)
and restart it.
Checking
Deployment
Tomcat
Open a web-browser to view the Tomcat manager page, http://localhost:8080/manager/html
(assuming it is running on the local host and port 8080; you will need
the Tomcat admin username and password to access this page). This shows
a list of deployed web applications and their status.
- If there is no entry at all for your web application then the
deployment failed completely and/or Tomcat has not picked it up; try
deploying again; try restarting Tomcat.
- If there is an entry for you web application but it shows
"Running" as "false" then there was an error during start-up of the web
application. See trouble shooting, below.
- If the entry for you application shows "Running" as "true" then
click through to the page(s) of your web application (e.g. the /equip2minimalwebapp link in
the file manager, or a direct URL, http://localhost:8080/equip2minimalwebapp/).
You should now see the index page of your web application. If not: try
restarting Tomcat; See Trouble shooting, below.
You should be good to go!
Jetty
Open a web-browser to view the Jetty top-level page, http://localhost:8080/. Although it
returns a 404 error it should list the known application contexts,
including the newly deployed equip2minimalwebapp/.
Assuming it does, click through to the web application itself, http://localhost:8080/equip2minimalwebapp/.
You should see the index page of your web application. If not: try
restarting Tomcat; See Trouble shooting, below.
Trouble Shooting
Common problems include:
- incorrect database name/username/password in etc/hibernate.cfg.xml - try
accessing the database directly using a standard console or graphical
client for that database and check that the name/username/password are
OK.
- EQUIP log directory (see EQUIP2_WebApp_Configuring_and_Building.html#dataspace_logging)
does not exist - check the configuration in webapp/WEB-INF/applicationContext.xml
and/or the error reports in the application output, and fix
configuration or create logging directory to match.
- mis-typed bean names in the Spring XML configuration files -
check error output(s) and find use of mis-spelling in configuration
files & fix.
- Tomcat has not been restarted since a significant change was made
(almost anything except an updated JSP page) and/or the change has not
been deployed to Tomcat - deploy the web app, restart tomcat
- a database class has been changed and it doesn't restart, or
throws new errors - Hibernate is also to automatically make some schema
changes (e.g. adding a new property to a class), but (a) this doesn't
always work (b) it cannot do some other changes, e.g. change of
property type, so if you change a class held in the database the safest
thing is to stop the web application, drop the table from the database
(using your preferred database client) and restart the application -
the table should be recreated correctly during start-up.
Tomcat
Depending on how the application has gone wrong and when, relevant log
information may be:
- in the logfiles in the Tomcat installation's log directory, e.g. C:\Program Files\Apache Software
Foundation\Tomcat 5.5\log in particular,
- catalina.*.log -
top-level information about starting/stopping web applications. On some
installations it may also include most of the console output
- stdout*.log - on
some installations, general console output will be here.
- in the web application's Log4j output files, the location of
which is configured in webapp/WEB-INF/log4j.properties,
e.g. in the Tomcat installation's directory for the web application,
e.g. C:\Program Files\Apache
Software Foundation\Tomcat
5.5\webapps\equip2minimalwebapp\WEB-INF\webapp.log
Jetty
Relevant output should be on the console (on
windows increase the buffer size for the console window). Check the
jetty configuration (by default etc/jetty.xml)
for configuration of other logging output(s). This may include:
- logs in the Jetty top-level log/
directory (may only be request logs by default)
- in the web application's Log4j output files, the location of
which is configured in webapp/WEB-INF/log4j.properties,
e.g. in the Jetty installation's directory for the web application,
e.g. .../webapps/equip2minimalwebapp/WEB-INF/webapp.log
Changes
2007-10-25
- note about jetty differences
2007-10-24
- Added initial information on Jetty as an alternative
- more information on using Jetty
2007-01-29
- Document created (based on part on existing DOF/lovecity docs)