Direct Web Remoting (DWR) is designed to be used with Java, one of the most widely used object-oriented languages. Java is not limited to any particular platform, but its main use has been server-side rather than desktop applications.
Although the actual installation of DWR is straightforward, there are a number of prerequisites that need to be taken care of first.
First, download the Java software development kit from http://java.sun.com. The following examples are based on the version 1.5 kit, so if you have an earlier version you will need to upgrade.
You have a number of options available at Sun's site that can be confusing at times. For development work, you basically have two choices: either the plain development kit (which will also install the runtime files necessary for all Java applications) or the one that includes the NetBeans IDE (Integrated Development Environment). All the examples in this chapter can be developed and run without the IDE. This can then be downloaded separately if you are moving on to more serious Java development.
You can then install the kit and the runtime and create or update any environment variables as detailed in the accompanying readme file.
Next, you will need a web server that supports Java servlets and JSP. The most common one is Tomcat, part of the Apache Jakarta project. There are versions available for Windows and UNIX/Linux, and details of how to install and configure them can be found at www.coreservlets.com/Apache-Tomcat-Tutorial/.
At the URL just given you will see that there is a ready-to-run version that has been pre-configured with a number of standard settings. That is the version that was used for this chapter's examples; other than modifying the server's port so that it didn't clash with IIS, it worked out of the box.
After the Java SDK and the Tomcat server are installed, you should be able to start up Tomcat as shown in the tutorial and navigate to the home page. This will give you access to the management pages as well as a number of test pages and samples that you can use to make sure everything is set up correctly.
Finally, obtain the DWR files from http://getahead.ltd.uk/dwr/. This is only a small download of about 150KB. The main file, dwr.jar, needs to be placed in a specific folder of your web application. Put these files aside until the basic folder structure has been created.
To set up a test site for DWR, create the folder structure, headed by DwrTest, as shown in Figure 10-5.
The next step is to create two XML configuration files: web.xml and dwr.xml. First, the basic structure of web.xml:
<web-app 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" version="2.4"> <servlet> <servlet-name>dwr-invoker</servlet-name> <display-name>DWR Servlet</display-name> <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping> </web-app>