create a .war file from gwt-project

derp picture derp · Mar 23, 2011 · Viewed 26.6k times · Source

How do I create a .war-file from my gwt-project in eclipse?

Answer

Chris Boesing picture Chris Boesing · Mar 23, 2011

I always use Ant build file, so the project gets compiled and packaged as a war with one click.

Add an xml-file to your project with the following content:

<project name="test" basedir="." default="default">
<property name="src.dir" value="src" />
<property name="build.dir" value="war" />
<path id="compile.classpath">
    <fileset dir="${build.dir}/WEB-INF/lib">
        <include name="**/*.jar" />
        <include name="**/*.xml" />
    </fileset>
</path>

<target name="default" depends="gwtc, buildwar,deploy">
</target>

<target name="gwtc" description="GWT compile to JavaScript">
    <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
        <classpath>
            <pathelement location="${src.dir}" />
            <path refid="compile.classpath" />
        </classpath>
        <arg line="-logLevel INFO" />
        <jvmarg value="-Xmx1024M" />
        <arg value="YourProject.EntryPointClass" />
    </java>
</target>

<target name="buildwar">
    <war basedir="war" destfile="YourProject.war" webxml="war/WEB-INF/web.xml">
        <exclude name="WEB-INF/**" />
        <webinf dir="war/WEB-INF/">
            <include name="**/gwt-servlet.jar" />
            <include name="**/classes/**" />
        </webinf>
    </war>
</target>

<target name="deploy">
    <copy file="YourProject.war" todir="." />
</target>

</project>

(Edit `YourProject.EntryPointClass to the path to your EntryPoint-class)

You would need to add gwt-user.jar and gwt-dev.jarto your projects build path(right click on your project -> Build Path -> Add External Achives).

If you now look at your "Problems"-view you get a warning that the two files are not available on the server's class path. You can use the QuickFix to either copy it to WEB-INF/lib or hide the warning. The build file will not include those two file in the war-file.

All you need to do to compile and create the file is to right click the xml-file and select run as Ant Build.