Hi all,

The following is a little scheme I came up with for configuring a
maven based gwt project. I specifically wanted to avoid using gwt-
maven-plugin as I've had some issues with it. It feels a bit redundant
too.

The example pom below is for an experimentation project that uses gwt,
the incubator and commons-io. The project layout uses the maven
standard /src/main/webapp for the exploded war and not /war as
google's gwt eclipse plugin does. To achieve this maven is configured
to output class files in /src/main/webapp/WEB-INF/classes and not
under /target. The clean plugin is also pointed to same output
locations so that mvn clean works.

The pom defines two profiles. One is the dev profile ( active by
default ) which also depends on the gwt-dev artifact for dev mode,
etc. The second is the web profile which is used for running the gwt
compiler ( for example by calling mvn -Pweb install ). The web profile
uses maven-antrun-plugin and ant's java task to run the gwt compiler.
A trivial bit of javascript is used to determine the processor count
on the current machine and so it's possible to pass the optimal -
localWorkers setting to the gwt compiler.

An ide launch configuration for dev mode would need to:
    * use com.google.gwt.dev.DevMode as main class
    * add src/main/java and src/main/resources to the classpath
    * add something like -
agentlib:jdwp=transport=dt_socket,address=1025,server=y,suspend=n to
the VM args to allow connecting a debugger to the web app
    * use something like this for the main class's arguments:
            -war src/main/webapp
            -startupUrl /index.html
            -codeServerPort 1026
            -port 1027
            com.example.TestGWT.TestGWT

If setting this up in, say, eclipse feels like too much clicking, it's
possible to achieve the same effect from a linux shell by:

running once:

cp=`mvn dependency:build-classpath | grep -E '^[^[]'`;

running every time you want to start dev mode:

ava -agentlib:jdwp=transport=dt_socket,address=1025,server=y,suspend=n
-Xms256m -Xmx512m -Xss50M -XX:PermSize=128m -XX:MaxPermSize=192m -cp
$cp:src/main/java:src/main/resources com.google.gwt.dev.DevMode -war
src/main/webapp -startupUrl /index.html -codeServerPort 1026 -port
1027 com.example.TestGWT.TestGWT

The entire pom:

<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.example</groupId>
    <artifactId>TestGWT</artifactId>
    <packaging>jar</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>TestGWT</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</
project.build.sourceEncoding>
        <gwtVersion>2.0.4</gwtVersion>
        <gwtIncubatorVersion>20100204-r1747</gwtIncubatorVersion>
        <maven.test.skip>true</maven.test.skip>
    </properties>
    <build>
        <outputDirectory>${basedir}/src/main/webapp/WEB-INF/classes</
outputDirectory>
        <testOutputDirectory>${basedir}/src/main/webapp/WEB-INF/
classes</testOutputDirectory>
        <resources>
            <resource>
                <directory>${basedir}/src/main/java</directory>
            </resource>
            <resource>
                <directory>${basedir}/src/test/java</directory>
            </resource>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>src/main/webapp/
com.example.TestGWT</directory>
                        </fileset>
                        <fileset>
                            <directory>src/main/webapp/WEB-INF/
classes</directory>
                        </fileset>
                        <fileset>
                            <directory>src/main/webapp/WEB-INF/lib</
directory>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-user</artifactId>
            <version>${gwtVersion}</version>
        </dependency>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-servlet</artifactId>
            <version>${gwtVersion}</version>
        </dependency>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-incubator</artifactId>
            <version>${gwtIncubatorVersion}</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.4</version>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>com.google.gwt</groupId>
                    <artifactId>gwt-dev</artifactId>
                    <version>${gwtVersion}</version>
                    <scope>runtime</scope>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>web</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>gwtc</id>
                                <phase>process-classes</phase>
                                <configuration>
                                    <tasks>
                                        <script language="javascript">
<![CDATA[
                                            cores =
java.lang.Runtime.getRuntime().availableProcessors();
 
java.lang.System.setProperty("coreCount", cores);
                                        ]]>
                                        </script>
                                        <java failonerror="true"
fork="true" classpathref="maven.plugin.classpath"
classname="com.google.gwt.dev.Compiler">
                                            <classpath>
                                                <pathelement
location="src/main/java" />
                                                <pathelement
location="src/test/java" />
                                                <path
refid="maven.compile.classpath" />
                                                <path
refid="maven.runtime.classpath" />
                                            </classpath>
                                            <jvmarg value="-Xmx256M" /
>
                                            <!-- Additional arguments
like -style PRETTY or -logLevel DEBUG -->
                                            <arg value="-war" />
                                            <arg value="${basedir}/src/
main/webapp" />
                                            <arg value="-
localWorkers" />
                                            <arg value="${coreCount}" /
>
                                            <arg
value="com.example.TestGWT.TestGWT" />
                                        </java>
                                    </tasks>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>org.apache.ant</groupId>
                                <artifactId>ant-apache-bsf</
artifactId>
                                <version>1.7.1</version>
                            </dependency>
                            <dependency>
                                <groupId>rhino</groupId>
                                <artifactId>js</artifactId>
                                <version>1.7R2</version>
                            </dependency>
                            <dependency>
                                <groupId>org.apache.ant</groupId>
                                <artifactId>ant-nodeps</artifactId>
                                <version>1.7.1</version>
                            </dependency>
                            <dependency>
                                <groupId>com.google.gwt</groupId>
                                <artifactId>gwt-dev</artifactId>
                                <version>${gwtVersion}</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

I hope this helps :)

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to