1.4. Packaging of the Application for Running on a Web Container

1.4.1. Creating the web.xml File

A web.xml file must be created to define a servlet for the remote service that was defined and the mapping must be done. The mapping must be the same as that used in the client when it was searching for the endpoint to use.

The following is an example of the xml file:

<?xml version="1.0" encoding="ISO-8859-1">
<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>ServletFacadeService</servlet-name>
    <servlet-class>org.objectweb.easybeans.demo.sudoku.web.server.service.ServletFacadeServiceImpl</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>ServletFacadeService</servlet-name>
    <url-pattern>/facade</url-pattern>
  </servlet-mapping>

</web-app>

1.4.2. Generating the AJAX Client that Will Be Embedded in the War File

GWT provides some shell scripts to generate the client side. However, it is recommended that an ant task be used.

First, define a classpath. This classpath should include GWT libraries and the path to the source code of the Entry point:

  <path id="gwt.classpath">
    <pathelement location="${project.dir}/src" />
    <pathelement location="${gwt.sdk.location}/gwt-user.jar" />
    <pathelement location="${gwt.sdk.location}/gwt-dev-windows.jar" />
  </path>

Then, compile the code:

  <target name="compile" description="Compile demo" depends="init">
    <javac srcdir="${src.dir}" destdir="${classes.dir}" debug="on">
      <classpath refid="base.classpath" />
    </javac>
  </target>

Finally, generate the GWT:

  <target name="generate-gwt" depends="compile">
    <java classname="com.google.gwt.dev.GWTCompiler" fork="true">
      <arg value="-out" />
      <arg value="${dist.www.dir}" />
      <arg value="org.objectweb.easybeans.demo.sudoku.web.Sudoku" />
      <classpath refid="base.classpath" />
    </java>
  </target>

1.4.3. Packaging of the .war File

The AJAX client will be bundled in a war file and will contain the GWT runtime library.

The war task of ant can be used to create the package.

The output generated by the GWT compiler is added at the root of the WAR file; the libraries go in the WEB-INF/lib folder, and all classes go in the WEB-INF/classes folder.

  <target name="build.war"
          description="Build war file"
          depends="compile, generate-gwt">
    <war jarfile="${dist.webapps.dir}/sudoku.war"
         webxml="${resources.dir}/web.xml">
      <fileset dir="${dist.www.dir}/org.objectweb.easybeans.demo.sudoku.web.Sudoku" />
      <lib dir="${lib.dir}">
        <include name="gwt-servlet.jar" />
        <include name="ow_easybeans_component_smartclient.jar" />
      </lib>
      <classes dir="${classes.dir}">
        <include name="**/**" />
      </classes>
    </war>
  </target>
[Warning] Warning

The gwt-servlet.jar is used and not the gwt-user.jar file. This is because gwt-user.jar provided by Google contains javax.servlet.* classes, and thus it cannot be deployed on a Tomcat container.