Hi,
I have found a workaround for the infamous command line length problem
in gwt-maven on windows so am posting it for those that may find it
useful.

The idea is to use a multi module project similar to the example (rpc,
server, gwt) but NOT include a dependency on server in the gwt module
[which means the gwt compiler now only has to cope with the rpc module
and its dependencies (which should be very few) on its classpath]

Of course this means that the war generated by the gwt module is now
no longer deployable as it is missing the server code and its
dependencies. So create a final empty (no code) maven module "war"
which just depends on server and gwt.

The rpc module has to supply source code. Rather than including it in
the main jar as a resource I use the attach-sources method of the
source plugin described on the wiki : 
http://code.google.com/p/gwt-maven/wiki/M2FAQ
This is not essential and in fact complicates things (as seen below)
but does avoid the sources being packaged in the final war.

Unfortunately depending on the source artifact in provided scope as
described on the wiki does not work on windows - the build fails as
the gwt compiler cannot find the sources. It works on windows when
building the gwt module alone (but not when building the top level
module) and at all times on linux.

The reason for this is that maven does not include the attached source
artifact in multimodule projects on the compile time classpath but
_does_  include it on the compile time _test_ classpath. Is this a
maven bug? The gwt-maven
ScriptWriterUnix.getPrintWriterWithClasspath() method explicitly adds
the test classes whereas the ScriptWriterWindows class does not
(anyone know the reason for this difference?)

To avoid this problem I use the system scope for the source dependency
in the gwt module :
        <dependency>
            <!-- non existant artifact ID required (-source) maven
bug?? -->
            <artifactId>myproject-rpc-source</artifactId>
            <groupId>${project.groupId}</groupId>
            <version>${project.version}</version>
            <classifier>sources</classifier>

            <!-- hack below as maven only incudes provdied in test
scope -->
            <scope>system</scope>
            <systemPath>${basedir}/../rpc/target/myproject-rpc-$
{project.version}-sources.jar</systemPath>
        </dependency>

The above is sufficient to build a working war even on windows but
breaks gwt hostmode (as the gwt:gwt goal now no longer includes the
server jars on the classpath).
My solution is to use an ant script to start gwt host mode :

<project name="myproject-gwt" default="gwt-hostmode">
    <target name="gwt-hostmode" depends="_copy-gwt-hostmode">
        <mkdir dir="tmp"/>
        <antcall target="_execMaven">
            <param name="mavenCmdLine" value="com.totsp.gwt:maven-
googlewebtoolkit2-plugin:mergewebxml gwt:gwt"/>
        </antcall>
    </target>

    <target name="_copy-gwt-hostmode">
<!-- here you can copy any extra files such as applicationContext, gwt
rpc files etc -->

        <!-- ensure sources are available -->
        <property name="tomcat.libs" value="target/tomcat/webapps/ROOT/
WEB-INF/lib"/>
        <antcall target="_execMaven">
            <param name="mavenCmdLine" value="dependency:copy-
dependencies -DoutputDirectory=${tomcat.libs} -
DincludeClassifiers=sources -DincludeScope=system -DexcludeGrou
pIds=com.google.gwt"/>
        </antcall>

        <!-- copy services (to avoid command line length problem on
win2k) -->
        <antcall target="_execMaven">
            <param name="mavenCmdLine" value="-f hostmode-pom.xml
dependency:copy-dependencies -DoutputDirectory=${tomcat.libs} -
DincludeScope=provided"/>
        </antcall>
    </target>

    <target name="_execMaven">
        <exec executable="mvn" osfamily="unix">
            <arg line="${mavenCmdLine}"/>
        </exec>

        <!-- on windows mvn is really mvn.bat which ant cant't execute
directly...
        TODO: look ant maven ant tools
        -->
        <exec executable="cmd" osfamily="windows">
            <arg line="/c mvn.bat ${mavenCmdLine}"/>
        </exec>
    </target>
</project>

This requires an extra pom file (hostmode-pom.xml) which has the
dependency on the server module:
<project>
    <parent>
        <artifactId>myproject</artifactId>
        <groupId>com.mycompany</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <groupId>${parent.groupId}</groupId>
    <artifactId>myproject-gwt-hostmode</artifactId>
    <version>${parent.version}</version>

    <dependencies>
        <dependency>
            <artifactId>myproject-services</artifactId>
            <groupId>${project.groupId}</groupId>
            <version>${project.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>

Hope this is useful to someone.

Martin Fuzzey

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"gwt-maven" group.
To post to this group, send email to gwt-maven@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/gwt-maven?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to