views:

80

answers:

0

I tried to set up a Maven project, which supports the Google GWT tools and eclipse PDE integration.

I was only able to accomplish this by adding "gwt-dev-2.x.x.jar" and "gwt-user-2.x.x" to the bundle classpath. For this, I had to change their scope from provided to compile, which is highly undesirable as this greatly increases the size of the war file. Without adding these dependencies to the bundle classpath, eclipse would give the error message "Projects that use the web archive layout (WAR) must use GWT 1.6 or later."

Below an example project, which generates the eclipse project files on the command:

mvn eclipse:clean eclipse:eclipse -Declipse.pde -Declipse.useProjectReferences=false gwt:eclipse


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

        <modelVersion>4.0.0</modelVersion>
        <groupId>de.mxro.zz.samplegwt204project</groupId>
        <artifactId>zzSampleGWT204Project</artifactId>
        <packaging>war</packaging>
        <version>0.0.2-SNAPSHOT</version>
        <name>zzSampleGWT204Project</name>

        <!--  include pluginRepository and repository for GWT-Maven -->
        <pluginRepositories>
            <pluginRepository>
                <id>gwt-maven-plugins</id>
                <url>http://gwt-maven.googlecode.com/svn/trunk/mavenrepo/&lt;/url&gt;
            </pluginRepository>
            <pluginRepository>
                <id>gwt-plugin-repo</id>
                <url>http://google-web-toolkit.googlecode.com/svn/2.1.0.M3/gwt/maven&lt;/url&gt;
                <name>Google Web Toolkit Plugin Repository</name>
            </pluginRepository>
        </pluginRepositories>

        <repositories>
            <repository>
                <id>gwt-maven</id>
                <url>http://gwt-maven.googlecode.com/svn/trunk/mavenrepo/&lt;/url&gt;
            </repository>
            <repository>
                <id>codehaus-maven-repo</id>
                <name>Codehaus repo</name>
                <url>http://repository.codehaus.org/org/codehaus/mojo/&lt;/url&gt;
            </repository>
            <repository>
                <id>gwt-repo</id>
                <url>http://google-web-toolkit.googlecode.com/svn/2.1.0.M3/gwt/maven&lt;/url&gt;
                <name>Google Web Toolkit Repository</name>
            </repository>
        </repositories>

        <!--  convenience to define GWT version in one place -->
        <properties>
            <gwtVersion>2.0.4</gwtVersion>
        </properties>

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

            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
            </dependency>

            <dependency>
                <groupId>com.google.gwt</groupId>
                <artifactId>gwt-user</artifactId>
                <version>${gwtVersion}</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.google.gwt</groupId>
                <artifactId>gwt-dev</artifactId>
                <version>${gwtVersion}</version>
                <!-- <classifier>${platform}-libs</classifier>-->
                <!-- <type>zip</type>-->
                <scope>compile</scope>
            </dependency>
            <!--
                <dependency> <groupId>com.google.gwt</groupId>
                <artifactId>gwt-dev</artifactId> <version>${gwtVersion}</version>
                <classifier>${platform}</classifier> <scope>provided</scope>
                </dependency>
            -->

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

        <build>
            <plugins>
                <!--  The Maven bundle plugin generates Meta-data required for OSGi  -->
                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-bundle-plugin</artifactId>
                    <extensions>true</extensions>
                    <executions>
                        <execution>
                            <id>bundle-manifest</id>
                            <phase>process-classes</phase>
                            <goals>
                                <goal>manifest</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <supportedProjectTypes>
                            <supportedProjectType>jar</supportedProjectType>
                            <supportedProjectType>bundle</supportedProjectType>
                            <supportedProjectType>war</supportedProjectType>
                        </supportedProjectTypes>
                        <instructions>
                            <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
                            <Bundle-Version>${pom.version}</Bundle-Version>
                            <Embed-Dependency>gwt-servlet*,gwt-user*,servlet-api,gwt-dev*
                            </Embed-Dependency>
                            <Embed-Directory>target/dependency</Embed-Directory>
                            <Import-Package>*</Import-Package>
                            <!-- <Export-Package>*</Export-Package>-->
                            <_exportcontents>com.google.*</_exportcontents>
                        </instructions>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <configuration>
                        <archive>
                            <!-- add the generated manifest to the war -->
                            <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                        </archive>
                    </configuration>
                    <!--
                        <configuration> <webXml>war/WEB-INF/web.xml</webXml>
                        </configuration>
                    -->
                </plugin>
                <!--  configure the GWT-Maven plugin -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>gwt-maven-plugin</artifactId>
                    <version>1.3.1.google</version>
                    <configuration>
                        <logLevel>INFO</logLevel>
                        <style>PRETTY</style>
                        <gwtVersion>${gwtVersion}</gwtVersion>
                        <runTarget>/ZzSampleGWT204Project.html</runTarget>
                        <hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>
                        <!--
                            <modules>
                            <module>${project.groupId}.ZzSampleGWT204Project</module>
                            <module>${project.groupId}</module> </modules>
                        -->

                    </configuration>
                    <executions>
                        <execution>
                            <id>gwtcompile</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-eclipse-plugin</artifactId>
                    <!-- <version>2.7</version>-->  <!--  Note 2.8 does not work with AspectJ aspect path -->
                    <configuration>
                        <downloadSources>true</downloadSources>
                        <downloadJavadocs>true</downloadJavadocs>
                        <wtpversion>2.0</wtpversion>
                        <additionalBuildcommands>

                            <buildCommand>
                                <name>com.google.gwt.eclipse.core.gwtProjectValidator</name>
                            </buildCommand>
                        </additionalBuildcommands>
                        <additionalProjectnatures>

                            <projectnature>com.google.gwt.eclipse.core.gwtNature</projectnature>

                        </additionalProjectnatures>
                    </configuration>
                </plugin>


                <!--
                    Keep the MANIFEST.MF used by eclipse in sync with the MANIFEST.MF
                    created by the maven bundle plugin
                -->
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <tasks>
                                    <delete file="${basedir}/META-INF/MANIFEST.MF" />
                                    <copy file="${project.build.outputDirectory}/META-INF/MANIFEST.MF"
                                        tofile="${basedir}/META-INF/MANIFEST.MF" />
                                    <!--
                                        <copy file="target/classes/META-INF/MANIFEST.MF"
                                        tofile="${basedir}/META-INF/MANIFEST.MF" /
                                    -->
                                </tasks>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-dependency-plugin</artifactId>

                    <executions>
                        <!--
                            This additional execution can extract all the JARs of the
                            dependencies
                        -->
                        <!--
                            <execution> <id>unpack-dependencies</id>
                            <phase>generate-resources</phase> <goals>
                            <goal>unpack-dependencies</goal> </goals> <configuration>
                            <includeGroupIds>${module.unpackDependencyGroups}
                            </includeGroupIds> </configuration> </execution>
                        -->

                        <execution>
                            <id>copy-dependencies</id>
                            <phase>process-sources</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${basedir}</outputDirectory>
                                <overWriteReleases>false</overWriteReleases>
                                <overWriteSnapshots>false</overWriteSnapshots>
                                <overWriteIfNewer>true</overWriteIfNewer>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <!--  Cleanup necessary because of PDE tweaks -->
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>2.3</version>
                    <configuration>
                        <filesets>
                            <fileset>
                                <directory>${basedir}</directory>
                                <includes>
                                    <include>*.jar</include>
                                </includes>
                                <followSymlinks>false</followSymlinks>
                            </fileset>
                        </filesets>
                    </configuration>
                </plugin>
                <!--  tell the compiler we can use 1.5 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                    </configuration>
                </plugin>
            </plugins>
            <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
        </build>


    </project>