What you need in your POM:
- GWT dependencies (at least a gwt user is never deployed to a server; a gwt servlet for GWT-RPC or other server-side support, classes already included in gwt-user; gwt-dev and gwt-codeserver are recommended, it depends the plugin you will use, never deploy them).
- GWT-Maven plugin; there are two of them:
org.codehaus.mojo:gwt-maven-plugin (which version should match the version of GWT you are using) and net.ltgt.gwt.maven:gwt-maven-plugin (still in beta; works with any version of GWT)
Depending on the plugin, you will use a different packaging and plugin configuration.
Last but not least, you really need to use different Maven modules for client and server code, and also, possibly, a third module for general code. However, for a small project, using one module may be enough (but you will have to add some settings / hacks to your POM if you do not want to deploy your client classes on your server).
This gives us for a single-module project (mixed client and server code in one project) with the CodeHaus Mojo plugin:
<?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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>test</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <dependencyManagement> <dependencies> <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt</artifactId> <version>2.7.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <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>com.google.gwt</groupId> <artifactId>gwt-codeserver</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt-servlet</artifactId> <scope>runtime</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>gwt-maven-plugin</artifactId> <version>2.7.0</version> <executions> <execution> <goals> <goal>compile</goal> </goals> </execution> </executions> <configuration> <module>com.example.test.Test</module> </configuration> </plugin> </plugins> </build> </project>
And use mvn gwt:run to run DevMode (which will also run your server code with some limitations).
Or for the net.ltgt plugin:
<?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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>test</artifactId> <version>1.0-SNAPSHOT</version> <packaging>gwt-app</packaging> <dependencyManagement> <dependencies> <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt</artifactId> <version>2.7.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <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>com.google.gwt</groupId> <artifactId>gwt-codeserver</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt-servlet</artifactId> <scope>runtime</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>net.ltgt.gwt.maven</groupId> <artifactId>gwt-maven-plugin</artifactId> <version>1.0-beta-1</version> <extensions>true</extensions> <configuration> <moduleName>com.example.test.Test</moduleName> <launcherDir>${project.build.directory}/${project.build.finalName}</launcherDir> </configuration> </plugin> </plugins> </build> </project>
And use mvn gwt:codeserver to run SuperDevMode (client-side code only). You will have to use the plugty-maven-plugin or tomcat7-maven-plugin to run your server code.
For a multi-module project, take a look at my archetypes: https://github.com/tbroyer/gwt-maven-archetypes I transfer them to net.ltgt, simplifying the process of launching them (no longer need mvn install ; mvn gwt:codeserver was designed for multi-module projects, unlike CodeHaus Mojo gwt:run and gwt:run-codeserver )
Disclaimer: I am a supporter of both plugins, but I would approve of my own plugin, which IMO fixes a lot of quirks and errors and the legacy of CodeHaus Mojo.
Thomas Broyer
source share