views:

8390

answers:

5

Does anyone know of a good guide for creating a project with the new 2.0 release of GWT using maven and eclipse? I am running into a lot of problems getting them to play nicely together.

For what it's worth, I can create a gwt project using the maven eclipse plugin which works fine, but porting it to maven doesn't work (so a guide for this would be great).

Likewise, I can use the maven plugin (gwt-maven-plugin), but when I import it to eclipse (import -> materialize maven projects), it does not get recognised as a GWT project...

Thanks

+20  A: 

EDIT: I've updated my answer with additional steps provided by the OP. Credits to the OP for the details.

I just broke my Eclipse setup trying to install the latest version of the Google Plugin for Eclipse (for GWT 2.0) so I can't confirm everything but, let's assume the following prerequisites are fulfilled:

Did you try to:

  1. Create a new project from Eclipse (New > Other... then select Maven Project and choose the gwt-maven-plugin archetype).

  2. Edit the generated pom.xml, update the gwt.version property to 2.0.0 (which has been released in the central repo), add the Codehaus Snapshot repository and set the gwt-maven-plugin version to 1.2-SNAPSHOT (the version 1.2 isn't released in central, this should happen soon) 1.2 (which has been released in central too).

  3. Add a <runTarget> to the gwt-maven-plugin configuration as documented in Using the Google Eclipse Plugin.

  4. Configure the maven-war-plugin as documented in the page mentioned in the previous step.

  5. Manually enable GWT on the project from project preference by setting the Use Google Web Toolkit checkbox This step is unnecessary since you'll be building/running with a Maven run configuration, not the GWT Plugin for Eclipse.

This is how my pom.xml actually looks like:

<?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"&gt;
  <!--
    GWT-Maven archetype generated POM
  -->
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.demo</groupId>
  <artifactId>my-gwtapp</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>gwt-maven-archetype-project</name>

  <properties>

      <!-- convenience to define GWT version in one place -->
      <gwt.version>2.0.0</gwt.version>

      <!--  tell the compiler we can use 1.5 -->
      <maven.compiler.source>1.5</maven.compiler.source>
      <maven.compiler.target>1.5</maven.compiler.target>

  </properties>

  <dependencies>

    <!--  GWT dependencies (from central repo) -->
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <version>${gwt.version}</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <version>${gwt.version}</version>
      <scope>provided</scope>
    </dependency>

    <!-- test -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.4</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <outputDirectory>war/WEB-INF/classes</outputDirectory>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>generateAsync</goal>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <runTarget>com.mycompany.demo.gwt.Application/Application.html</runTarget>
        </configuration>
      </plugin>
      <!--
          If you want to use the target/web.xml file mergewebxml produces,
          tell the war plugin to use it.
          Also, exclude what you want from the final artifact here.
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webXml>target/web.xml</webXml>
                    <warSourceExcludes>.gwt-tmp/**</warSourceExcludes>
                </configuration>
            </plugin>
            -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <warSourceDirectory>war</warSourceDirectory>
          <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
        </configuration>
      </plugin>    
    </plugins>
  </build>

</project>

Run the gwt:eclipse goal (using m2eclipse Maven2 > build...) to setup your environment and create the launch configuration for your GWT modules.

Run gwt:compile gwt:run to compile and run a GWT module in the GWT Hosted mode.

Pascal Thivent
Thanks for the reply. Did as in your post, but also did the additional steps of specifying the GWT SDK (rightclick on project->google-> Web Toolkit settings). It does seem to compile, but when running the project (in eclipse), I don't get any links in the Development Mode tab to open up the app... Any ideas why this is the case?
Lehane
Ok, so I (finally) got it to work. Although there still seems to be a problem with eclipse development mode displaying a link to the application. Essentially follow Pascal's answer, but then follow the instructions on http://mojo.codehaus.org/gwt-maven-plugin-1.1/eclipse/google_plugin.html. Then use "mvn gwt:compile gwt:run" to view the pages.@Pascal - If you want to append your answer to reflect that you have to (1) specify in eclipse that the project is a gwt one, (2) change the pom as indicated in the page above, and (3) run 'mvn gwt:eclipse' before compiling I'll accept the answer.
Lehane
Thanks for the feedback. I've updated my answer accordingly (I've tested this, everything works fine). Thanks again!
Pascal Thivent
I'm using gwt-maven-plugin without Google Eclipse Plugin.Project is created with gwt-maven-plugin archetype.Everything works fine except gwt:debug.GWT development mode window does not open.I can't access page with gwt module.What am I doing wrong?
Chobicus
Found a solution on:http://claudiushauptmann.com/tutorial-gwt-maven-and-eclipse-with-m2eclipse.html
Chobicus
Thanks for the great post, very helpful!
sdoca
@sdoca You're welcome. Glad it was helpful.
Pascal Thivent
Informative post. Though, Step 5 is unnecessary since you'll be building/running with a Maven run configuration, not the GWT Plugin for Eclipse.
rpr
@rpr: You're right, will update that. Thanks for pointing that out.
Pascal Thivent
A: 

I am getting no url in my dev mode window. any ideas?

Dan Billings
@Dan: This should probably be asked as a separate question. Look for the "Ask Question" button at the top right of the page. You'll be able to link to this question if you want to refer to it in your new one. Also, welcome to Stack Overflow!
Bill the Lizard
A: 

Hey everybody,

I tried to get my project working with GWT 2.0 and Maven. Unfortunately your guide didn't work. I'm always getting this message:

Build errors for qm_mvn; org.apache.maven.lifecycle.LifecycleExecutionException: Missing:
----------
1) com.google.gwt:gwt-user:jar:2.0.0

Try downloading the file manually from the project website.

  Then, install it using the command: 
      mvn install:install-file -DgroupId=com.google.gwt -DartifactId=gwt-user -Dversion=2.0.0 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there: 
      mvn deploy:deploy-file -DgroupId=com.google.gwt -DartifactId=gwt-user -Dversion=2.0.0 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency: 
    1) com.myproject:qm_mvn:war:0.0.1-SNAPSHOT
    2) com.google.gwt:gwt-user:jar:2.0.0

----------
1 required artifact is missing.

for artifact: 
  com.myproject:qm_mvn:war:0.0.1-SNAPSHOT

from the specified remote repositories:
  central (http://repo1.maven.org/maven2)

and

Offline / Missing artifact com.google.gwt:gwt-servlet:jar:2.0.0:runtime
Offline / Missing artifact com.google.gwt:gwt-user:jar:2.0.0:provided

my pom.xml looks like this:

<?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"&gt;
  <!--
    POM generated by gwt-maven-plugin archetype
  -->
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.myproject</groupId>
  <artifactId>qm_mvn</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>

  <properties>

      <!-- convenience to define GWT version in one place -->
      <gwt.version>2.0.0</gwt.version>

      <!--  tell the compiler we can use 1.5 -->
      <maven.compiler.source>1.5</maven.compiler.source>
      <maven.compiler.target>1.5</maven.compiler.target>

  </properties>

  <dependencies>

      <!--  GWT dependencies (from central repo) -->
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-servlet</artifactId>
      <version>${gwt.version}</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.google.gwt</groupId>
      <artifactId>gwt-user</artifactId>
      <version>${gwt.version}</version>
      <scope>provided</scope>
    </dependency>

    <!-- test -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.7</version>
      <scope>test</scope>
    </dependency>
  </dependencies>



  <build>
    <outputDirectory>war/WEB-INF/classes</outputDirectory>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>gwt-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>generateAsync</goal>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <runTarget>com.myproject.qm_mvn.Application/Application.html</runTarget>
        </configuration>
      </plugin>
        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <warSourceDirectory>war</warSourceDirectory>
          <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
        </configuration>
      </plugin> 
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.0.2</version>
          <configuration>
            <source>${maven.compiler.source}</source>
            <target>${maven.compiler.target}</target>
          </configuration>
      </plugin>
    </plugins>
  </build>

</project>

If I change the GWT version to 1.7.1 it works. So is it possible that the 2.0.0 version isn't in the central?

Thanks for your answers.

wolfi
A: 

Just in case. If you use Google GIN in your project you should add compile goal before gwt:compile. So the whole sequence would be:

compile gwt:compile gwt:run

You can read explanation here: http://code.google.com/p/google-gin/wiki/GinTutorial#Compilation

Roman Chervotkin
A: 

Just a question how would you do to generate a project with a name different from Application ?

sampras