Packing GWT to WAR

37 views
Skip to first unread message

rbell

unread,
Feb 6, 2008, 10:34:26 AM2/6/08
to Google Web Toolkit
I am struggling with setting up and packaging my GWT into a WAR. It
was not initially created with either Ant or Maven, and the only
experience I have with Ant is the ubiquitous "Hello World" example in
their documentation. I must admit that I have tried learning how to
use both Ant and Maven and am struggling to understand them as well.

The RPC service that I have created works well in the shell mode, but
creates an invocation exception when being used on Tomcat. This again
makes me think that I am not able to package this program correctly.

The gwt-maven documentation is too thin for me to understand, and
someone else recommended Ant and declared it to be easy, but did not
mention how to set that up either.

Any help would be greatly appreciated, thanks.

Brock Parker

unread,
Feb 6, 2008, 10:47:09 AM2/6/08
to Google Web Toolkit
I had a similar problem a while back. Make sure that your web.xml
defines your RPC servlet. For example:

<web-app>
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>com.blah.MyServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>/com.blah.MyApplication/myServlet</url-pattern>
</servlet-mapping>
</web-app>

Hope that helps.

Brock

rbell

unread,
Feb 6, 2008, 11:10:43 AM2/6/08
to Google Web Toolkit
Thanks for the response Brock

This is my web.xml file:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<!-- Servlet Definitions -->
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>server.MyServletImpl</servlet-class>
</servlet>

<!-- Servlet URL Mappings -->
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/myService</url-pattern>
</servlet-mapping>

</web-app>

my directory structure:
WEB-INF
--classes
------client
----------MyServlet.class
----------MyServletAsync.class
------public
------server
----------MyServletImpl.class
------MyApp.gwt.xml
--lib
------gwt-servlet.jar
------gwt-user.jar
------ojdbc6.jar
--web.xml

Original class structure in Eclipse was :
dot.gis.
-client
-public
-server

Tomcat server error log:
Feb 6, 2008 8:30:06 AM org.apache.catalina.core.StandardWrapperValve
invoke
SEVERE: Allocate exception for servlet MyServlet
java.lang.ClassNotFoundException: dot.gis.server.MyServlet
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:
1358)
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:
1204)
at
org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:
1083)
at
org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:
806)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
129)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
175)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
263)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
844)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:
447)
at java.lang.Thread.run(Unknown Source)
Feb 6, 2008 9:16:38 AM org.apache.catalina.core.StandardWrapperValve
invoke
INFO: Servlet MyServlet is currently unavailable

Thanks again

j3t

unread,
Feb 6, 2008, 12:25:00 PM2/6/08
to Google Web Toolkit
http://www.charisacademy.com/GWT/CreateWar.htm

On 6 Feb., 17:10, rbell <rnb...@iastate.edu> wrote:
> Thanks for the response Brock
>
> This is my web.xml file:
>
> <web-app xmlns="http://java.sun.com/xml/ns/javaee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

Eric Ponthiaux

unread,
Feb 6, 2008, 2:35:46 PM2/6/08
to Google-We...@googlegroups.com
Use maven for this , and it will be a piece of cake .

Kind regards

rbell

unread,
Feb 6, 2008, 4:04:01 PM2/6/08
to Google Web Toolkit
Thanks j3t and Eric, unfortunately I think my problem is in my service
now, and not so much in my ability to package the war file correctly.
I packaged the war and had Tomcat deploy it on first execution and it
still threw an InvocationExceptionError my way.

Eric: I wouldn't mind using maven for this, but again as I stated
previously, I am having trouble making heads or tails of maven.

Thanks Again.

Brock Parker

unread,
Feb 6, 2008, 4:43:51 PM2/6/08
to Google Web Toolkit
You shouldn't need gwt-user.jar in your war file. I would try taking
that out first. Also, I'm not sure if it's required or not but I have
the stuff generated under www in my war file as well. There should be
a folder like com.blah.MyApplication under www in your project. The
root of my war looks like:

- WEB-INF
- META-INF
- com.blah.MyApplication

I don't know if that's necessary, but at least it's working. :)

SlavaC

unread,
Feb 7, 2008, 5:14:24 AM2/7/08
to Google Web Toolkit
I think the problem is in your WAR structure. MyServletImpl.class
should be located in the package it was originialy in.

Suggested WAR structure:
WEB-INF
--classes
----dot
-------gis
----------client
--------------MyServlet.class
--------------MyServletAsync.class
----------public
----------server
--------------MyServletImpl.class
----------MyApp.gwt.xml

Also the Servlet Definitions in your web.xml should point to
dot.gis.server.MyServlet.

At least that's how it is in my configuration and it is working fine.

On Feb 6, 6:10 pm, rbell <rnb...@iastate.edu> wrote:
> Thanks for the response Brock
>
> This is my web.xml file:
>
> <web-app xmlns="http://java.sun.com/xml/ns/javaee"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
> org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.ja­va:
> 1358)
>         at
> org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.ja­va:
> 1204)
>         at
> org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:
> 1083)
>         at
> org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:
> 806)
>         at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.j­ava:
> 129)
>         at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.j­ava:
> 175)
>         at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
> 128)
>         at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
> 102)
>         at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.jav­a:

gregor

unread,
Feb 7, 2008, 9:57:05 AM2/7/08
to Google Web Toolkit
hi rbell,

If you put together both what Brock and SlavaC have said (and you need
to do both), you should be fine, They have identified your two
problems I think: Specifically

a) alter your build to structure WAR to reflect correct source package
structure as per SlavaC above.
b) change your web.xml as per Brock to this:

<web-app>
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>dot.gis.server.MyServletImpl</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/dot.gis.MyApp/MyServlet</url-pattern>
</servlet-mapping>
</web-app>

c) make sure your RPC call client side
matches .setServiceEntryPoint(GWT.getModuleBaseURL() + "MyServlet")

regards
gregor



On Feb 7, 10:14 am, SlavaC <Cuc...@gmail.com> wrote:
> I think the problem is in your WAR structure. MyServletImpl.class
> should be located in the package it was originialy in.
>
> Suggested WAR structure:
> WEB-INF
> --classes
> ----dot
> -------gis
> ----------client
> --------------MyServlet.class
> --------------MyServletAsync.class
> ----------public
> ----------server
> --------------MyServletImpl.class
> ----------MyApp.gwt.xml
>
> Also the Servlet Definitions in your web.xml should point to
> dot.gis.server.MyServlet.
>
> At least that's how it is in my configuration and it is working fine.
>
> On Feb 6, 6:10 pm, rbell <rnb...@iastate.edu> wrote:
>
> > Thanks for the response Brock
>
> > This is my web.xml file:
>
> > <web-app xmlns="http://java.sun.com/xml/ns/javaee"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/we..."

rbell

unread,
Feb 7, 2008, 3:13:48 PM2/7/08
to Google Web Toolkit
I got everything working. Thanks for the help!!!

Now if only I understood ant or maven well enough to make the task of
compiling and updating tomcat a little faster.
> > > Thanks againThanks

rbell

unread,
Feb 7, 2008, 4:31:11 PM2/7/08
to Google Web Toolkit
Okay, now I'm just struggling, getting Tomcat to start/stop from ant
tasks, the search continues!!!

On Feb 7, 3:13 pm, rbell <rnb...@iastate.edu> wrote:
> I got everything working. Thanks for the help!!!
>
> Now if only I understood ant or maven well enough to make the task of
> compiling and updating tomcat a little faster.
>
> On Feb 7, 9:57 am, gregor <greg.power...@btinternet.com> wrote:
>
> > hi rbell,
>
> > If you put together both what Brock and SlavaC have said (and you need
> > to do both), you should be fine, They have identified your two
> > problems I think: Specifically
>
> > a) alter your build to structureWARto reflect correct source package
> > structure as per SlavaC above.
> > b) change your web.xml as per Brock to this:
>
> > <web-app>
> > <servlet>
> > <servlet-name>MyServlet</servlet-name>
> > <servlet-class>dot.gis.server.MyServletImpl</servlet-class>
> > </servlet>
>
> > <servlet-mapping>
> > <servlet-name>MyServlet</servlet-name>
> > <url-pattern>/dot.gis.MyApp/MyServlet</url-pattern>
> > </servlet-mapping>
> > </web-app>
>
> > c) make sure your RPC call client side
> > matches .setServiceEntryPoint(GWT.getModuleBaseURL() + "MyServlet")
>
> > regards
> > gregor
>
> > On Feb 7, 10:14 am, SlavaC <Cuc...@gmail.com> wrote:
>
> > > I think the problem is in yourWARstructure. MyServletImpl.class

ssylvis

unread,
Feb 7, 2008, 5:08:44 PM2/7/08
to Google Web Toolkit
You can use Ant to create your webapp WAR then deploy it to Tomcat. No
restarts necessary.

To create your WAR file, use the "war" task. You will have to use the
"java" task to hook into the GWTCompiler and compile your Java to
JavaScript/HTML before generating the WAR. Something like this:

<java classname="com.google.gwt.dev.GWTCompiler" dir="${bld.web}"
fork="true">
<arg value="-style" />
<arg value="DETAILED" />
<arg value="${webapp.full.name}" />
<classpath>
<path refid="path.main.all" />
<path refid="path.gwt.res" />
</classpath>
</java>
<!-- Construct the war file from the GWT-compiled files. -->
<war destfile="${bld.web}/${deploy.name}.war" webxml="$
{webapp.package.path}/deploy/web.xml">
<fileset dir="${bld.web}/${webapp.full.name}" />
<classes dir="${obj.main}" includes="**/*.class" />
<lib dir="${lib}" includes="*.jar, *.so" />
</war>

See here: http://ant.apache.org/manual/CoreTasks/war.html.

To deploy, see here:
http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html#Executing%20Manager%20Commands%20With%20Ant.

gregor

unread,
Feb 7, 2008, 6:50:18 PM2/7/08
to Google Web Toolkit
Absolutely. It's easy and quick.

here's one of mine you may find useful to crib from. So long as your
happy to use the build directory under your project directory (i.e.
next to \src), and your OK with setting GWT_HOME as an environment
variable (you can replace that with full paths to the GWT jars if you
want) you can probably just copy this into your project directory and
edit build.properties with your details - it should work (but check
the fileset in the classpath and lib in the war task for any other
jars your app needs - I always put all mine under "lib" as you can
see).

build.properties:

deploy=C:/jboss-4.0.4/server/default/deploy
module=IPSV
package=com.willow.gwt.ipsv
url=http://localhost:8080/${ant.project.name}/${package}.${module}/$
{module}.html
war=${ant.project.name}.war

build.xml:


<?xml version="1.0" encoding="UTF-8"?>
<project name="IPSV" default="deploy" basedir=".">

<property environment="env"/>
<property file="build.properties"/>

<path id="classpath">
<pathelement location="build"/>
<pathelement location="src"/>
<pathelement location="${env.GWT_HOME}/gwt-user.jar"/>
<pathelement location="${env.GWT_HOME}/gwt-dev-windows.jar"/>
<pathelement location="${env.GWT_HOME}/gwt-servlet.jar"/>
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</path>

<target name="clean"
description="deletes all generated files">
<delete dir=".gwt-cache"/> <!-- generated by GWT -->
<delete dir="build"/> <!-- generated by the prepare target -->
</target>


<target name="compile" depends="prepare"
description="compiles Java source files to bytecode">
<javac srcdir="src" destdir="build"
classpathref="classpath" debug="true">
</javac>
</target>

<target name="compile.gwt" depends="compile"
description="compiles Java source files to JavaScript">
<!-- Consider adding -Xms256m -Xmx512m to improve performance. -->
<java classname="com.google.gwt.dev.GWTCompiler"
classpathref="classpath" fork="true">
<!--<arg line="-logLevel INFO"/>
<arg line="-gen build/review"/> -->
<arg line="-out build/www"/>
<!-- <arg line="-treeLogger"/> -->
<arg line="-style OBFUSCATE"/>
<!--<arg value="${module}"/> -->
<arg value="${package}.${module}"/>
</java>
</target>

<target name="deploy" depends="war"
description="deploys the war file to Tomcat">
<copy file="build/${war}" todir="${deploy}"/>
<echo>browse ${url}</echo>
</target>


<target name="prepare" description="creates output directories">
<mkdir dir="build"/>
</target>


<target name="war" depends="compile, compile.gwt"
description="builds the war file">
<delete file="build/${war}"/>
<war warfile="build/${war}" webxml="WEB-INF/web.xml">
<!-- bytecode from your Java code -->
<classes dir="build" includes="**/*.class"/>
<!-- generated HTML/JavaScript plus your CSS -->
<fileset dir="build/www"/>
<!-- supplied JAR -->
<lib file="${env.GWT_HOME}/gwt-servlet.jar"/>
<lib dir="lib">
<include name="**/*.jar"/>
</lib>
</war>
</target>

</project>

regards
gregor


On Feb 7, 10:08 pm, ssylvis <ssyl...@gmail.com> wrote:
> You can use Ant to create your webapp WAR then deploy it to Tomcat. No
> restarts necessary.
>
> To create your WAR file, use the "war" task. You will have to use the
> "java" task to hook into the GWTCompiler and compile your Java to
> JavaScript/HTML before generating the WAR. Something like this:
>
> <java classname="com.google.gwt.dev.GWTCompiler" dir="${bld.web}"
> fork="true">
> <arg value="-style" />
> <arg value="DETAILED" />
> <arg value="${webapp.full.name}" />
> <classpath>
> <path refid="path.main.all" />
> <path refid="path.gwt.res" />
> </classpath>
> </java>
> <!-- Construct the war file from the GWT-compiled files. -->
> <war destfile="${bld.web}/${deploy.name}.war" webxml="$
> {webapp.package.path}/deploy/web.xml">
> <fileset dir="${bld.web}/${webapp.full.name}" />
> <classes dir="${obj.main}" includes="**/*.class" />
> <lib dir="${lib}" includes="*.jar, *.so" />
> </war>
>
> See here:http://ant.apache.org/manual/CoreTasks/war.html.
>
> To deploy, see here:http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html#Executing%....
Reply all
Reply to author
Forward
0 new messages