I firstly generated a gwt maven project by executing --

mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.7.0

After that, the pom.xml is as follows:

        <?xml version="1.0" encoding="UTF-8"?>
    <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">

      <modelVersion>4.0.0</modelVersion>
      <groupId>com.boye.games</groupId>
      <artifactId>games-gwt</artifactId>
      <packaging>war</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>GWT Maven Archetype</name>

      <properties>
        <!-- Convenience property to set the GWT version -->
        <gwtVersion>2.7.0</gwtVersion>

        <!-- GWT needs at least java 1.6 -->
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>

      <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt</artifactId>
            <version>${gwtVersion}</version>
            <type>pom</type>
            <scope>import</scope>
          </dependency>
        </dependencies>
      </dependencyManagement>

      <dependencies>
        <dependency>
          <groupId>com.google.gwt</groupId>
          <artifactId>gwt-servlet</artifactId>
          <scope>runtime</scope>
        </dependency>
        <dependency>
          <groupId>com.google.gwt</groupId>
          <artifactId>gwt-user</artifactId>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>com.google.gwt</groupId>
          <artifactId>gwt-dev</artifactId>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.11</version>
          <scope>test</scope>
        </dependency>
      </dependencies>

      <build>
        <!-- Output classes directly into the webapp, so that IDEs and "mvn process-classes" update them in DevMode -->
        <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>

        <plugins>

          <!-- GWT Maven Plugin -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>2.7.0</version>
            <executions>
              <execution>
                <goals>
                  <goal>compile</goal>
                  <goal>test</goal>
                  <goal>generateAsync</goal>
                </goals>
              </execution>
            </executions>
            <!-- Plugin configuration. There are many available options, see 
              gwt-maven-plugin documentation at codehaus.org -->
            <configuration>
              <runTarget>LineThree.html</runTarget>
              <modules>
                <module>com.boye.games.linethree.LineThree</module>
              </modules>
            </configuration>
          </plugin>
        </plugins>
      </build>

    </project>

Then I imported this project into eclipse via built-in eclipse function -- import existing Maven project.

However, the process failed due to several reasons:

  1. GreetingServiceAsync cannot be resolved to a type
  2. Execution default of goal org.codehaus.mojo:gwt-maven-plugin:2.7.0:generateAsync failed:

Plugin org.codehaus.mojo:gwt-maven-plugin:2.7.0 or one of its dependencies could not be resolved: Failed to collect dependencies for org.codehaus.mojo:gwt-maven-plugin:jar:2.7.0 () (org.codehaus.mojo:gwt-maven-plugin:2.7.0:generateAsync:default:generate-sources)

  1. google plugin can't identify this project as gwt web application automatically.

My environment as follows:

  1. java version 1.7.0_03
  2. eclipse version Kepler Service Release 2
  3. gwt version 2.7.0

Please advice, thanks a lot!

4

There are 4 answers

1
Bo Ye On BEST ANSWER

I did another attempt to try in a win32 computer, the problem re-appeared even if I set up the environment as aforementioned working in my win64 computer.

So I really got confused, like Klarki said, I have to do some tweaks to get it work. I generated GreetingServiceAsync via mvn gwt:generateAsync then manually copy GreetingServiceAsync to source folder, then I remove <goal>generateAsync</goal> in pom.xml, then import project via eclipse's existing maven project. It works again!

Sadly see it not working intelligently.

1
klarki On

The problem was with generateAsync, which in your case generates GreetingServiceAsync on execution. Eclipse probably wasn't configured to handle it properly and this class was not generated and eclipse reported the missing class warning.

Another thing that could be done to get the project to work was to run mvn package from command line and add the generated dir in target dir as source dir in eclipse (vie right clicking the project and selecting New -> source folder > browsing folder name > target > generated-sources > the right folder)

Also you may run into same issue after you do mvn clean - the generated GreetingServiceAsync will be deleted and the problem may come back.

The problem exists because eclipse isn't tightly integrated with maven and uses its own build system ignoring maven targets that you don't have plugins for. What you could do is to open eclipse preferences > maven > lifecycle mappings and there you can enable generateAsync to execute.

If you copy the generated class manually you have to keep in mind that you need to update it when needed, where as it is intended to generate automatically. So you loose this convenience.

2
Bo Ye On

After I changed my environment as follows:

  1. java version "1.8.0_05"
  2. eclipse Version: Luna Release (4.4.0)
  3. Google plugin for Eclipse 4.4

I works like a charm.

Probably, it's a version incompatibility issue.

0
teteArg On

This work for me:

I deleted the local maven gwt repository, in windows 7 it's in C:\Users\.m2\repository\com\google\gwt, and then make a

mvn clean complile

so maven re-import al dependencys.