0

I'm using gwt with maven plugin. My web.xml looks like this:

<web-app 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" xmlns="http://java.sun.com/xml/ns/javaee">

<!-- Servlets -->
<servlet>
    <servlet-name>queryServiceImpl</servlet-name>
    <servlet-class>com.vo.search.server.QueryServiceImpl</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>queryServiceImpl</servlet-name>
    <url-pattern>/admin/queryService</url-pattern>
</servlet-mapping>

<!-- Default page to serve -->
<welcome-file-list>
    <welcome-file>Admin.html</welcome-file>
</welcome-file-list>
</web-app>

And my module Admin.gwt.xml looks like this :

<module rename-to='admin'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name="com.google.gwt.core.Core" />
<inherits name='com.google.gwt.user.User' />
<inherits name="com.google.gwt.i18n.I18N" />
<inherits name="com.google.gwt.i18n.CldrLocales" />
<inherits name="com.google.gwt.user.theme.clean.CleanResources" />

<!-- Enable debug ID. -->
<inherits name="com.google.gwt.user.Debug" />
<set-property name="gwt.enableDebugId" value="true" />

<!-- We need the JUnit module in the main module, -->
<!-- otherwise eclipse complains (Google plugin bug?) -->
<!-- <inherits name='com.google.gwt.junit.JUnit' /> -->

<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.clean.Clean' />
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->

<!-- Other module inherits -->

<!-- Specify the app entry point class. -->
<entry-point class='com.vo.search.client.Admin' />

<!-- Specify the app entry point class. -->

<!-- Specify the paths for translatable code -->
<source path='client' />
<source path='shared' />


</module>

Finally, my pom.xml looks like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.vo.search</groupId>
<artifactId>search-admin</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>Admin</name>

<properties>
    <!-- Convenience property to set the GWT version -->
    <gwtVersion>2.5.0-rc1</gwtVersion>
    <!-- GWT needs at least java 1.5 -->
    <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-servlet</artifactId>
        <version>${gwtVersion}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <version>${gwtVersion}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.7</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
        <classifier>sources</classifier>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <!-- Generate compiled stuff in the folder used for developing mode -->
    <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>

    <plugins>

        <!-- GWT Maven Plugin -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>2.5.0-rc1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test</goal>
                        <goal>i18n</goal>
                        <goal>generateAsync</goal>
                    </goals>
                </execution>
            </executions>
            <!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
                documentation at codehaus.org -->
            <configuration>
                <runTarget>Admin.html</runTarget>
                <hostedWebapp>${webappDirectory}</hostedWebapp>
                <i18nMessagesBundle>com.vo.search.client.Messages</i18nMessagesBundle>
            </configuration>
        </plugin>

        <!-- Copy static web files before executing gwt:run -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>exploded</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <webappDirectory>${webappDirectory}    </webappDirectory>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

Building and running the project works fine. When trying to access the page I see in the console :

[WARN] Aliased resource: file:/C:/workspaces/search/admin-mvn/search-admin/src/main/webapp/admin/admin.nocache.js==file:/C:/workspaces/search/admin-mvn/search-admin/src/main/webapp/Admin/Admin.nocache.js
[WARN] Aliased resource: file:/C:/workspaces/search/admin-mvn/search-admin/src/main/webapp/admin/admin.nocache.js==file:/C:/workspaces/search/admin-mvn/search-admin/src/main/webapp/Admin/Admin.nocache.js
[WARN] 404 - GET /admin/admin.nocache.js (127.0.0.1) 1408 bytes
   Request headers
      Host: 127.0.0.1:8888
      Connection: keep-alive
      User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like     Gecko) Chrome/22.0.1229.39 Safari/537.4
      Accept: */*
      Referer: http://127.0.0.1:8888/Admin.html?gwt.codesvr=127.0.0.1:9997
      Accept-Encoding: gzip,deflate,sdch
      Accept-Language: en-US,en;q=0.8
      Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
   Response headers
      Content-Type: text/html; charset=iso-8859-1
      Content-Length: 1408

I think the problem is that it looks for file admin.nocache.js in admin dir but the generated dir is actually Admin even though my rename-to attribute is admin in the module configuration file. Changing the rename-to attribute to match didn't help.

Here's my project organization created by gwt-maven-plugin archetype: enter image description here

Jean-Michel Garcia
  • 2,359
  • 2
  • 23
  • 44
Michael
  • 22,196
  • 33
  • 132
  • 187
  • 1
    Well, I think the problem is that you have an `Admin/Admin.nocache.js` in `src/main/webapp` to begin with. – Thomas Broyer Sep 10 '12 at 08:49
  • @ThomasBroyer can you elaborate please ? – Michael Sep 10 '12 at 08:57
  • Generated code should only be in `target`, not `src`. I don't know why you have `Admin/Admin.nocache.js` in `src/main/webapp` but fix that first. – Thomas Broyer Sep 10 '12 at 10:24
  • @ThomasBroyer I've used gwt maven generate archetype to generate this dir structure. I'm not sure about how to do what you suggest. here is my project structure : http://tinypic.com/r/r93fut/6 from what i see it's pretty consistent with the project organization detailed in the plugin doc : http://mojo.codehaus.org/gwt-maven-plugin/user-guide/project.html – Michael Sep 10 '12 at 10:57
  • 1
    I'd recommend *not* using the archetype. All I've seen about it (as maintainer of the plugin) are bug reports. You'd have better luck starting from scratch. See http://stackoverflow.com/q/9703599/116472 – Thomas Broyer Sep 10 '12 at 12:45

2 Answers2

1

Please check your Admin.html. I think admin.nocache.js should be:

<script type="text/javascript" language="javascript" src="../admin/admin.nocache.js"></script>

Your file ... search-admin/src/main/webapp/Admin/Admin.nocache.js

Should be here: ... search-admin/src/main/Admin/Admin.nocache.js

Ivan Dyachenko
  • 1,348
  • 9
  • 16
  • It hasn't occured to me to check in `Admin.html`. Indeed it was `src="admin/admin.nocache.js"` isntead `src="Admin/Admin.nocache.js"` but I will leave it under `webapp` dir. I still don't understand the way maven determines how to name the module directory under `webapp` dir. I thought it was determined in the `Admin.gwt.xml` file with the `rename-to` attribute, but when i set it to `admin` it still creates the directory as `webapp\Admin` and not `webapp\admin` – Michael Sep 10 '12 at 12:35
  • I haven't studied your POM in details, but clearly you shouldn't have anything being _generated_ into `src` (i.e. that should be your goal). Are you using `mvn gwt:run` to launch the DevMode? – Thomas Broyer Sep 10 '12 at 12:42
  • @ThomasBroyer code is being generated into target as well. I don't see anywhere in the `pom.xml` something that tells it to compile it into `src`. No matter where I change the module to `admin` the directory being created is still `Admin` – Michael Sep 10 '12 at 12:50
  • 1
    Please read http://mojo.codehaus.org/gwt-maven-plugin/user-guide/compile.html // The compiler will output the generated javascript in the project output folder (${project.build.directory}/${project.build.finalName}). For a WAR project, this matches the exploded web application root. You can also configure the plugin to compile in ${basedir}/src/main/webapp that may better match using lightweight development process based on to the "inplace" mode of the war plugin. To enable this, just set the inplace parameter to true. – Ivan Dyachenko Sep 10 '12 at 12:54
  • @Michael: how are you launching the DevMode? And do you have another `gwt.xml` file in your source tree? – Thomas Broyer Sep 10 '12 at 13:05
  • @ThomasBroyer I don't have another `gwt.xml` file. I am lunching DevMode by right clicking the project and clicking run as web application (google web application) which gives me the address to open in my web browser. Also tried to run as you suggested, `mvn gwt:run` which gave the same result – Michael Sep 10 '12 at 13:09
  • OK, so you're not using the gwt-maven-plugin to launch the DevMode, and you're probably launching it the wrong way. – Thomas Broyer Sep 10 '12 at 13:10
  • @ThomasBroyer That could be another problem... but still compilation results in building module dir as `webapp\Admin` instead of `webapp\admin` and I don't know how to change this behavior. – Michael Sep 10 '12 at 13:12
  • 1
    On Windows, if the folder already exists with a different case, Windows will simply use it, it won't recreate it or change its name (and won't create a sibling one, as that would cause a _conflict_). Did you remove the folders in between tests? – Thomas Broyer Sep 10 '12 at 13:16
  • @ThomasBroyer I removed `Admin` dir from `src\webapp` and ran mvn compile again. The directory wasn't created again there, but it was created under `target\search-admin-1.0\admin` so i guess it was an old dir like you said. – Michael Sep 10 '12 at 13:37
1

If you launch the DevMode using the Google Plugin for Eclipse (and not mvn gwt:run), then follow those rules: https://developers.google.com/eclipse/docs/faq#gwt_with_maven

Particularly, and most importantly, do not choose src/main/webapp as the WAR directory, this is why DevMode generates file in there, and it can only cause you problems: GWT module may need to be (re)compiled REDUX

Community
  • 1
  • 1
Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • I thought moving to Maven would be straightforward, now I see that it's not. So I have to investigate a little more. I had a working regular gwt project and I thought the best way mavenizing it would be to create a gwt maven archetype and copy all of the source files into it. In your opinion, what is the best way of organizing the project ? – Michael Sep 10 '12 at 13:19
  • 1
    Have a look at [my archetypes](github.com/tbroyer/gwt-maven-archetypes). There's still some work needed, but the overall idea is there: separate client and server code in distinct modules, don't use `src/main/resources` for GWT client resources (UiBinder templates, CssResource stylesheets, Messages properties files, etc.) as they are part of the sources to be compiled. My ultimate goal is to create some custom Maven packaging types and lifecycles but we're not there yet. – Thomas Broyer Sep 10 '12 at 13:43