Howto execute maven-antrun-plugin after gwt:gwt phase

43 views
Skip to first unread message

Malte

unread,
Oct 17, 2008, 7:16:11 AM10/17/08
to gwt-maven
I want to execute the maven-antrun-plugin after I have closed the
GWTShell. I tryed following configuration:
<execution>
<id>rpcPolicyCopy</id>
<phase>gwt</phase>
<configuration>
<copy toDir="${basedir}/target/tomcat/webapps/ROOT">
<fileset dir="${basedir}/target/${artifactId}-${version}/.gwt-tmp/
shell">
<include name="**/*.gwt.rpc"/>
</fileset>
</copy>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
But nothing happend after closing the shell. Maybe someone could help
me?

Charlie Collins

unread,
Oct 17, 2008, 1:31:04 PM10/17/08
to gwt-maven
I am not sure exactly why you need to do this, but I guess that's a
different topic ;). But, for the record, "gwt" is not a "phase."

Here are the phases (well, some of the common ones):
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html.

The GwtMojo is bound to the compile phase.

Malte

unread,
Oct 18, 2008, 8:02:24 AM10/18/08
to gwt-maven
Cause the *.gwt.rpc file is generated during the execution of the
GWTShell, or I am wrong? I know I can generated it by compiling the
sources but want a solution where it is not necessary.

Charlie Collins

unread,
Oct 18, 2008, 10:12:00 AM10/18/08
to gwt-maven
The normal way to generate the .gwt.rpc files is with the compiler.
The shell does generate them too, for it's own use, at the first call
to onCreate (I believe). You shouldn't need to mess with those files
though, unless you are doing something atypical in the shell (like not
using GwtShellServlet because you are using some other means to map
the calls, etc).

Under normal circumstances, the serialization policy files will end up
in the war GWT-Maven builds by default (because of the compiler), if
they are needed (mvn install), and they end up in the shell and work
fine in the shell because it creates what it needs. You don't
normally ever need to mess with them.

Malte

unread,
Oct 18, 2008, 12:18:03 PM10/18/08
to gwt-maven
I will now run compile before calling the first time the shell and
copy the file to his new destination. But thanks for the advise with
the phases.

Charlie Collins

unread,
Oct 18, 2008, 4:25:31 PM10/18/08
to gwt-maven
"I will now run compile before calling the first time the shell and
copy the file to his new destination"

You don't need to do that at all, unless you aren't using
GwtShellServlet. ?

Malte

unread,
Oct 18, 2008, 5:53:07 PM10/18/08
to gwt-maven
It's a litte bit more complicated. I am running spring in the embedded
tomcat server and call the gwt shell servlet over the
DispatcherServlet from spring, because the default servlet-mapping /*
for the gwt shell servlet doesn't let me call any other servlet. When
I am now calling the gwt shell servlet from the spring context, the
gwt shell servlet is not able to find the gwt.rpc file in the .gwt-tmp/
shell directory. I don't know exactly why, but I think it is when I am
calling the gwt shell servlet from inside spring the servlet context
changed to the tomcat/webapps/ROOT directory. That why I have to copy
the gwt.rpc file to this directory. When someone can tell me how I can
change the context back to the default directory or how I can
configure the servlet-mapping so that I can call spring besides the
gwt shell servlet I would be happy ;)

Some configurations:

<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</
servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>shell</servlet-name>
<servlet-class>com.google.gwt.dev.shell.GWTShellServlet</servlet-
class>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!--inserted by gwt-maven-->
<servlet-mapping>
<servlet-name>shell</servlet-name>
<url-pattern>/</url-pattern>

Problem is then the shell has the /* mapping everything is handled by
this servlet, cause all other mappings will overwritten by this. So I
let all servlet calls handled by spring. Folling configuration will
handle that:

<bean id="gwtShellController"
class="org.springframework.web.servlet.mvc.ServletForwardingController">
<property name="servletName">
<value>shell</value>
</property>
</bean>

<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/*/user.rpc">userController</prop>
<prop key="/*">gwtShellController</prop>
</props>
</property>
</bean>

My main goal is to run everything in the hosted browser with the
embedded tomcat server, without calling a jetty instance.

Charlie Collins

unread,
Oct 19, 2008, 7:26:32 AM10/19/08
to gwt-maven
Yeah, something like that is what I thought this was probably about,
and hence why I said "You shouldn't need to mess with those files
though, unless you are doing something atypical in the shell". Trying
to replace the GwtShellServlet is definitely atypical.

I am not sure how to help with changing the context, nor how to change
the mapping of the shell servlet. But, I know this has come up in
several other projects that use Spring and redirect things through the
shell servlet. You might check the GWT-SL (gwt server library)
project, as there is some info there about it.

I think in general though, those projects just use noserver and don't
try to configure the embedded Tomcat (I don't personally like that
approach, but that is usually what they do I think). You can still
run the shell with noserver, you just lose the ability to run
gwttestcase based tests, and get auto refresh of everything, etc.

Malte

unread,
Oct 20, 2008, 10:59:09 AM10/20/08
to gwt-maven
I tryed jetty, but I had only problems. Is there any example project
that uses jetty+gwt+spring? Would be very helpful.

Malte

unread,
Oct 28, 2008, 5:42:39 PM10/28/08
to gwt-maven
OK, I solved all my problems. I configured everything as folled:

pom.xml
------------------
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppSourceDirectory>
${basedir}/target/${artifactId}-${version}/
your.application.Application
</webAppSourceDirectory>
</configuration>
</plugin>


<!-- configure the GWT-Maven plugin -->
<plugin>
<groupId>com.totsp.gwt</groupId>
<artifactId>maven-googlewebtoolkit2-plugin</artifactId>
<version>2.0-beta24</version>
<configuration>
<compileTargets>
<value>
your.application.Application
</value>
</compileTargets>
<runTarget>
${artifactId}/Application.html
</runTarget>
<logLevel>INFO</logLevel>
<style>DETAILED</style>
<noServer>true</noServer>
<port>8080</port>
<extraJvmArgs>-Xmx512m -Xms128m</extraJvmArgs>
<gwtVersion>${gwtVersion}</gwtVersion>
</configuration>
<executions>
<execution>
<goals>
<goal>gwt</goal>
<goal>compile</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>applicationContextCopy</id>
<phase>process-classes</phase>
<configuration>
<tasks>
<copy toDir="${basedir}/target/${artifactId}-${version}/
your.application.Application">
<fileset dir="${basedir}/src/main/webapp/">
<include name="**/*.xml"/>
</fileset>
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

web.xml
----------------
<!-- Initialise the Spring MVC DispatcherServlet -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-
class>org.springframework.web.servlet.DispatcherServlet</servlet-
class>
<load-on-startup>1</load-on-startup>
</servlet>

<!-- Map the DispatcherServlet to only intercept RPC requests -->
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.rpc</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>Application.html</welcome-file>
</welcome-file-list>

spring.xml
-------------------
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/your.rpc">yourController</prop>
</props>
</property>
</bean>

I used the gwt-sl library to integrate gwt in spring.

Keep the default directory structure and then execute following
commands:
mvn jetty:run
mvn gwt:gwt

I hope this will help all that are new in spring and gwt-maven. Please
post if you have questions or improvements.

Greetz
Malte

Charlie Collins

unread,
Oct 28, 2008, 7:06:42 PM10/28/08
to gwt-maven
Good work sir. I will post this stuff in the Wiki-FAQ when I get a
chance., great info.

Malte

unread,
Oct 30, 2008, 8:05:31 PM10/30/08
to gwt-maven
If it would be helpful I can upload a example application that
contains all that stuff like GWT + Spring + Hibernate + Maven + Jetty.
But currently I have a little problem cause my jetty runs out of
memory after a few changes and also restarts when I am making changes
in the client package.

Malte

unread,
Nov 3, 2008, 4:38:39 AM11/3/08
to gwt-maven
For all who tryed my approach and get OutOfMemoryExceptions after some
jetty restarts. I figure out that there is an issue for CGLib + Spring
+ Hibernate + Sun JVM. This issue is open since a long time... The
best solution I found was to use the JRockit VM instead of Sun JVM.
Downloadable from: http://commerce.bea.com/products/weblogicjrockit/jrockit_prod_fam-bea.jsp
Reply all
Reply to author
Forward
0 new messages