views:

226

answers:

3

Over the past few days I have been trying to create/run a project in Eclipse using the gwt-maven-plugin and keep running into roadblocks (see some of my previous questions). I like to use Maven to do my builds, but I'm at the point where I'm thinking of going the Ant build route because of the complications of using Maven.

Does anyone out there have it configured/working well? Is it just me or is this harder than it should be?

A: 

For Eclipse I use: m2eclipse plugin (1.0). It works well with one or two minor things. Also download the m2eclipse-extras plugin to add SVN functionality AND Maven (or CVS if you prefer).

When you download then your project it reads the pom.xml and [re]creates the Eclipse configuration files like the mvn eclipse:eclipse command.

For GWT... I've used it too. It's a pretty twiked configuration but it works. I use GWT 2.0.3, the maven-gwt-plugin uses the dependencies to work (no ref to GWT SDK) and it can debug from Eclipse which is simply great.

You have to compile to a war directory (not the target/classes standard). But the details are in my work, so let me see it tomorrow and complete this answer :) Don't give up. It's a great thing to have GWT+Eclipse+Maven.

Edit: part of my configuration

<build>...
<outputDirectory>war/WEB-INF/classes</outputDirectory>
...
</build>


        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>1.2</version>
            <configuration>
                <gwtVersion>${gwt.version}</gwtVersion> <!-- para forzar que use el de maven y no el SDK instalado -->
                <disableCastChecking>true</disableCastChecking>
                <disableClassMetadata>true</disableClassMetadata>
                <runTarget>/subscriber/listSubscribers.htm</runTarget>
                <webappDirectory>${basedir}/war</webappDirectory>
                <soyc>true</soyc>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>


                    <!-- dont know/remember if the jetty inside the gwt uses this... but it doesnt hurt-->
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>6.1.14</version>
            <configuration>
                        <webAppConfig>
                        <contextPath>/magazine</contextPath>
                        <baseResource implementation="org.mortbay.resource.ResourceCollection">
                        <resourcesAsCSV>
                                ${basedir}/src/main/webapp,
                                ${basedir}/war
                            </resourcesAsCSV>
                        </baseResource>
                </webAppConfig>
                <connectors>
                    <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                        <port>8888</port>
                        <maxIdleTime>60000</maxIdleTime>
                    </connector>
                </connectors>
                <scanIntervalSeconds>3</scanIntervalSeconds>
                <scanTargets>
                    <scanTarget>${basedir}/war</scanTarget>
                </scanTargets>                  
            </configuration>
        </plugin>

AND

For debugging I create two tasks:

1) maven build inside eclipse that runs two goals: war:exploded gwt:debug

  • The first one copies all the resources into war directory for gwt debug to use them.
  • Next the gwt is ready.

Maybe you need to execute gwt:compile for the first time

2) a Java Remote Application debug configuration, with your project selected.

You run this configuration when the gwt:debug is "listening at port 8000"

AND: this is in a parent pom.xml (sorry I'll edit this post later :)

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1-alpha-2</version>
            <configuration>
                <warSourceDirectory>${basedir}/src/main/webapp</warSourceDirectory>
                <webappDirectory>${basedir}/war</webappDirectory>
                <warName>${artifactId}</warName>
            </configuration>
        </plugin>
helios
I should have mentioned that I also use the m2eclipse plugin. I don't believe I have the extras but we use Mercurial as our versioning system. I have set the maven-war-plugin warSourceDirectory to the "war" directory. I *think* I am doing things as I should, but keep running into issues. Currently I can't run gwt:debug because I get the error _[ERROR] Failed to execute goal org.codehaus.mojo:gwt-maven-plugin:1.2:debug (default-cli) on project MyProject: Command [[ ...<snip>...]] failed with status 1_ and I don't know why...
sdoca
Hi, I've spent some time the last few days trying to get GWT/Maven to work in Eclipse based on this blog (http://googlewebtoolkit.blogspot.com/2010/08/how-to-use-google-plugin-for-eclipse.html), but to no avail. When you said "no ref to GWT SDK" did you mean that you do not have the GWT Eclipse plugin installed?
sdoca
Nope. I meant that the gwt-maven-plugin uses the very gwt-user and gwt-servlet dependencies (hmmm... I didn't include that in the example) for compiling the GWT part of the project.
helios
It is: gwt-maven-plugin can use the gwt sdk home directory or your dependencies. It worked for me with the dependencies so no ref to any GWT SDK local path was necessary.
helios
+2  A: 

It is harder then it should be, however it is possible. All hints posted here can do the trick. However you can still have classloading issues. I decided to switch to GWT 2.1 and use new abilities of JettyLauncher. You can create own jetty launcher like this:

public class MyJettyLauncher extends com.google.gwt.dev.shell.jetty.JettyLauncher {
  @Override
  protected WebAppContext createWebAppContext(TreeLogger logger, File appRootDir) {
    return new WebAppContext(appRootDir.getAbsolutePath(), "/");
  }
}

And then add -server MyJettyLauncher option to your gwt launcher configuration. With such configuration all the libraries are managed by m2eclipse (you can even remove GWT SDK from classpath) and there is no need to copy anything to WEB-INF/lib (you can remove gwt-servlet.jar which could be already there).

Ready launcher is here in tadedon library: http://code.google.com/p/tadedon/source/browse/tadedon-gwt-dev/src/main/java/com/xemantic/tadedon/gwt/dev/JettyLauncher.java

morisil
A: 

After much frustration trying to get things to play nicely together, this is the setup I have that "works" for me. "Works" meaning that I can create, run and debug a GWT project with tweaks, but it isn't the most elegant solution.

Create Project

Much of the steps are the same as Pascal's answer in this post: http://stackoverflow.com/questions/1894003/maven-gwt-2-0-and-eclipse. I'll list mine out to be clear.

In Eclipse (Helios) with m2eclipse and GWT Eclipse plugins installed:

Create a new Maven project using the gwt-maven-plugin archetype

Modify the pom.xml:

  • set <gwt.version property> to 2.0.4 (needs to be same as GWT Eclipse Plugin version)
  • set <maven.compiler.source> and <maven.compiler.target> properties to 1.6
  • remove <goal>generateAsync</goal> from gwt-maven-plugin <plugin> config
  • add maven-war-plugin to pom.xml

maven-war-plugin example:

<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>

Update project Properties:

  • Google -> Web Toolkit, check the "Use Google Web Toolkit" box, and ensure "Use default SDK (GWT-2.0.4) is selected.

Run Maven "gwt:eclipse" goal on project (sets up environment and launch config)

Copy *.launch file to workspace.metadata.plugins\org.eclipse.debug.core.launches

Restart Eclipse

Compile/Run Project

I created a Run Configuration that does mvn clean compile gwt:run. The gwt:run is necessary to copy the resources and lib jars into the war directory. However, it does not copy the web.xml from src/main/webapp/WEB-INF into war/WEB-INF/. So, I have to manually copy that file.

If I want to run my application, the above step is sufficient. However, if I want to debug the application, I launch it by choosing the Google "Web Application" configuration from Debug Configurations that was created when the .launch file was copied previously. This configuration allows for debugging (breakpoints etc.) without any other config or need for remote debugging.

sdoca