Assembling a war file and deploying to Tomcat 5.x

34 views
Skip to first unread message

kannan

unread,
Nov 21, 2006, 12:26:40 AM11/21/06
to Google Web Toolkit
Hello,

I recently started developing some small app with GWT. The apps work
fine in the hosted mode as well as the Compile/Web app mode.

Now I would like to deploy this app to the Tomcat 5.x server.

I don't have any RPC code in my app.

I have searched this forum and got totally confused as to which method
to follow. I tried deploying the war file but couldn't open my
application html page.

In the web.xml should I be using the GWTShellServlet as shown below ?
If so, this class is not available during runtime ( meaning, when I
copy the gwt-dev-windows.jar to $TOMCAT_HOME/common/lib, tomcat
wouldn't start at all).

<web-app>

<servlet>
<servlet-name>UserAdmin</servlet-name>
<servlet-class>com.google.gwt.dev.shell.GWTShellServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>shell</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

</web-app>

I have stripped out the javax.* class files from gwt-user.jar and
copied this jar file to $TOMCAT_HOME/common/lib dir.

The app gets deployed successfully (my app dir gets created in the
webapps folder) but couldn't access any pages.

Any help in deploying this webapp would be greatly appreciated.

Really wondering why Google hasn't published any standard documentation
as to how to deploy on Tomcat or other web servers. Shouldn't be such
a pain to deploy the GWT web app.

Thanks,
Kannan

Luciano Broussal

unread,
Nov 21, 2006, 9:20:06 AM11/21/06
to Google Web Toolkit
Hi,

first to nt be confused by hosted and web mode gwt services deployment
use my universal class, of course you can leverage it. It works fro a
service call 'echo':

public class ServerFacade {

private String staticResponseURL;

private EchoServiceAsync remoteService;

private static ServerFacade instance;

private ServerFacade() {
staticResponseURL = GWT.getModuleBaseURL();
if (staticResponseURL.equals(""))
staticResponseURL = "/";

}

public String getBaseUrl() {
return staticResponseURL;
}

public EchoServiceAsync getRemoteService() {
if (remoteService == null) {
remoteService = (EchoServiceAsync) GWT.create(EchoService.class);
((ServiceDefTarget) remoteService)
.setServiceEntryPoint(staticResponseURL + "echo");
}
return remoteService;
}

public static ServerFacade get() {
if (instance == null) {
instance = new ServerFacade();
}
return instance;
}

}

Luciano Broussal

unread,
Nov 21, 2006, 9:25:29 AM11/21/06
to Google Web Toolkit
In hosted mode your module gwt file config should declare :

<servlet path='/com.dummy.DummyModule/echo'
class='com.dummy.server.EchoServiceImpl' />


In standelone tomcat server configuration your web.xml should have :

<servlet>
<description>Echo GWT service</description>
<display-name>Echo GWT service</display-name>
<servlet-name>echo</servlet-name>
<servlet-class>
com.dummy.server.EchoServiceImpl
</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>echo</servlet-name>
<url-pattern>
/com.dummy.DummyModule/echo
</url-pattern>
</servlet-mapping>


In fact in your war config deployement your service mapping is false.
substitute your values by mine with renaming for your purpouse of
course and it will works.

Luciano Broussal

http://lbroussal.blogspot.com

Luciano Broussal

unread,
Nov 21, 2006, 9:26:43 AM11/21/06
to Google Web Toolkit

charlie...@gmail.com

unread,
Nov 21, 2006, 9:42:55 AM11/21/06
to Google Web Toolkit
You can use the gwt-servlet.jar file at runtime in a container, that is
what it's for (you dont have to strip out stuff from gwt-user, just use
gwt-servlet). But that said that is also for server RPC side code.

As for deployment, if you have no RPC code, its just a matter of
copying the compiled "www" directory up. It does not even have to be a
Java container (Tomcat) where things are hosted. Once things are
compiled, GWT client side code, is just JavaScript and HTML. If your
app works fine compiled, as you state, and there is no RPC, then just
have a look around in the "www" folder the compile step creates. No
java anywhere to be deployed, no war file needed.

If you do have server side code, then of course you will need a Java
container, such as Tomcat, because you will have server side service
servlets, etc. For that you will need to have appropriate server
servlet entries in the deployment descriptor (web.xml), this is
something that currently you have to do on your own (or have build
scripts do it, Ant, Maven, etc - I use Maven to inspect the module
file, and make appropriate servlet entries in the web.xml file that
gets deployed, based on servlet entries in the module file). You do
not deploy the shell servlet, GWTShellServlet, that is only for "Hosted
Mode" as a shortcut.

I agree there should be more "deploy" documentation, and personally I
would like more support of app specific deployment descriptors
(web.xml) and Tomcat context files, in hosted mode (which also get
deployed - so I am using the same files, in addition to supporting
mocks as the toolkit does now). However, I think you may be
overcomplicating things if you have no server side RPC code, no war, no
nuthin, just HTML/JavaScript that you can host anywhere a browser can
get to it via HTTP.

kannan

unread,
Nov 21, 2006, 11:16:50 AM11/21/06
to Google Web Toolkit
Hello Charlie,

Thanks for your reply. You understood my problems correctly and have
provided good solutions.

To make my simple app (without RPC) work in Tomcat, all I had to do was
just to copy the contents of the "www" dir to Tomcat/webapps folder.

My next step is to introduce RPC code and would follow what you have
suggested.

Thanks again for your help.


Kannan

Javid

unread,
Nov 21, 2006, 11:43:25 AM11/21/06
to Google Web Toolkit
Kannan,
I found a ant build file that would package the app as a war file. All
I had to do for deployment was just put the file in the tomcat webapps
directory. It mde my life much much easier..

Javid


Ant.XML

<?xml version="1.0" encoding="utf-8" ?>
<project name="SagewebUI" default="all" basedir=".">
<description>
SagewebUI build file. This is used to package up your project as a
jar,
if you want to distribute it. This isn't needed for normal
operation.
</description>

<property name="gwt.module" value="evl.sage.SageUI"/>

<!-- set classpath -->
<path id="project.class.path">
<pathelement path="${java.class.path}/"/>
<pathelement path="C:/GWTLibrary/gwt-windows-1.2.22/gwt-user.jar"/>
<!-- Additional dependencies (such as junit) go here -->
<pathelement path="C:/javidWork/gwt-users/com-bouwkamp-gwt.jar"/>
<pathelement
path="C:/javidWork/JavaExternalLibs/gwt-widgets-0.1.2.jar"/>
<pathelement path="C:/javidWork/xmlrpxc-1.2-b1.jar"/>
</path>

<target name="javac" description="Compile src to bin">
<mkdir dir="bin"/>
<javac srcdir="src" destdir="bin" includes="**" debug="on"
debuglevel="lines,vars,source" source="1.4">
<classpath refid="project.class.path"/>
</javac>
</target>

<target name="jar" depends="javac" description="Package up the
project as a jar">
<mkdir dir="www/${gwt.module}/WEB-INF/lib"/>
<jar destfile="www/${gwt.module}/WEB-INF/lib/sageui.jar">
<fileset dir="bin">
<include name="**/*.class"/>
</fileset>
<!-- Get everything; source, modules, html files -->
<fileset dir="src">
<include name="**"/>
</fileset>
</jar>
</target>

<target name="gwt-compile" description="Compile to JavaScript">
<java classname="com.google.gwt.dev.GWTCompiler" fork="yes"
failonerror="true">
<classpath>
<pathelement location="src"/>
<pathelement
location="C:/GWTLibrary/gwt-windows-1.2.22/gwt-dev-windows.jar"/>
<pathelement
path="C:/javidWork/gwt-users/com-bouwkamp-gwt.jar"/>
<pathelement
path="C:/javidWork/JavaExternalLibs/gwt-widgets-0.1.2.jar"/>
<path refid="project.class.path"/>
</classpath>
<arg value="-out"/>
<arg file="www"/>
<arg value="${gwt.module}"/>
</java>
</target>

<target name="web-xml">
<mkdir dir="www/${gwt.module}/WEB-INF"/>
<echo file="www/${gwt.module}/WEB-INF/web.xml"><![CDATA[<?xml
version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>streamingServlet</servlet-name>
<servlet-class>evl.sage.server.StreamingServlet</servlet-class>
<load-on-startup>-1</load-on-startup>
</servlet>
<servlet>
<servlet-name>SageService</servlet-name>
<servlet-class>evl.sage.server.SageServiceImpl</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>streamingServlet</servlet-name>
<url-pattern>/streamingServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SageService</servlet-name>
<url-pattern>/sageService</url-pattern>
</servlet-mapping>
</web-app>
]]></echo>
</target>

<target name="war" depends="jar, gwt-compile, web-xml">
<mkdir dir="www/${gwt.module}/WEB-INF/lib"/>
<copy file="C:/GWTLibrary/gwt-windows-1.2.22/gwt-servlet.jar"
todir="www/${gwt.module}/WEB-INF/lib"/>
<copy file="C:/JavidWork/xmlrpc-1.2-b1.jar"
todir="www/${gwt.module}/WEB-INF/lib"/>
<jar destfile="sageui2.war" basedir="www/${gwt.module}"
duplicate="preserve"/>
</target>

<target name="clean">
<!-- Delete the bin directory tree -->
<delete dir="bin"/>
<delete dir="www/${gwt.module}"/>
<delete file="sageui2.war"/>
</target>

<target name="all" depends="war"/>

</project>

charlie...@gmail.com

unread,
Nov 21, 2006, 12:59:10 PM11/21/06
to Google Web Toolkit
You're welcome, glad it helped.

One other thing you may want to try with regard to the RPC stuff is
using something like the Maven myself and a few others have been
working on.

http://code.google.com/p/gwt-maven/

It's not well documented yet, I plan to put an example project up and
show how to use it and deploy to Tomcat, etc, but just havent gotten
there yet (will try to step that up this "holiday" week, if I get the
time). But anyway, the deal is that it will handle making a "war" file
suitable for tomcat for you. And when it makes said war file it will
create the web.xml entries necessary for service servlets automatically
(it has a task that inspects the GWT module file and then makes entries
in an app local web.xml file for them).

ant...@gmail.com

unread,
Dec 22, 2006, 9:02:02 PM12/22/06
to Google Web Toolkit
Is gwt-maven properly working at this time ?

I checked it out from svn

issued

maven gwt:war on the sample you provide

deployed the resulting .war into tomcat 5.5

without success :-(

I even twicked a little bit the data source in Tomcat Admin without
success :-(

god, why there is such poor documentation on deploying gwt RPC enabled
apps into application servers?! :-(

sle...@gmail.com

unread,
Jan 19, 2007, 5:51:28 PM1/19/07
to Google Web Toolkit

Thanks, after adjust a few of the paths this worked well. The only
thing I had an issue with is the ant target that creates the web.xml
file. There was some extra white space in the web.xml file that tomcat
5.5.17 was complaining about. After removing the extra white space the
app loaded and everything worked.

thanks!

Reply all
Reply to author
Forward
0 new messages