GWT, maven and using the standard maven src/main/webapp directory

We have changed some of our GWT projects back to using the standard maven location of src/main/webapp for the web resources. When we started these projects, the Eclipse GWT plug-in did not support that, so my colleagues insisted on using the war directory (I am an IntelliJ IDEA user/fan myself). Apart from being non-standard, this had the disadvantage that some generated content was also put in that directory cluttering the directory content and risking accident commits of these files (I know svn ignore can help, but still).

Unfortunately, the change was not as plain sailing as hoped. In fact, the gwt-maven-plugin seems to have some problems making this impossible. The advantage of open source solutions, you can create a patch :-).

Here are some excerpts from a pom configuration to make this work. To allow “mvn jetty:run” to work from a clean workspace:

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <version>6.1.20</version>
    <configuration>
        <webAppConfig>
            <contextPath>/</contextPath>
            <baseResource implementation="org.mortbay.resource.ResourceCollection">
                <!-- need both the webbapp dir and location where GWT puts stuff -->
                <resourcesAsCSV>src/main/webapp,${project.build.directory}/${project.build.finalName}</resourcesAsCSV>
            </baseResource>
        </webAppConfig>
        <reload>manual</reload>
    </configuration>
</plugin>

To allow “mvn gwt:run” to work from a clean workspace:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>gwt-maven-plugin</artifactId>
    <version>1.2-CPFIX</version>
    <configuration>
        <disableCastChecking>true</disableCastChecking>
        <disableClassMetadata>true</disableClassMetadata>
        <extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
        <module>org.geomajas.example.gwt.GeomajasSamples</module>
        <runTarget>samples.html</runTarget>
        <hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>clean</goal>
                <goal>generateAsync</goal>
                <goal>i18n</goal>
                <goal>compile</goal>
                <goal>test</goal>
            </goals>
        </execution>
    </executions>
</plugin>

You can find the patched version of the gwt-maven-plugin as version 1.2.CPFIX on the Geomajas repo http://maven.geomajas.org/. Details of the patch can be found in the their issue tracker.

Leave a Reply

Your email address will not be published. Required fields are marked *

question razz sad evil exclaim smile redface biggrin surprised eek confused cool lol mad twisted rolleyes wink idea arrow neutral cry mrgreen

*