How do I create a .war-file from my gwt-project in eclipse?
8 Answers
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.jar
to 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.

- 5,239
- 3
- 26
- 30
-
-
Should the direction wording in this answer, "the path to your EntryPoint-class", instead be "the path to your module file (
.gwt.xml)"? In my case (from the official GWT tutorial: http://www.gwtproject.org/doc/latest/tutorial/create.html), that ended up being "com.google.gwt.sample.stockwatcher.StockWatcher", where com was the first dir under src, and StockWatcher is the name of the .gwt.xml module file at the end of that path (using that made a successful compile & .war). Instead before that entering the path to the Java .class file of the EntryPoint-class did not work. – cellepo Oct 13 '15 at 23:03 -
Just pointing these [maybe obvious things] out for those who are helped by seeing it explicitly here... I'm not sure if it was absolutely necessary, but I also changed "
– cellepo Oct 13 '15 at 23:09 -
FYI: The .war will be placed at the root of your Eclipse project path. That was the same level as where I put this build.xml, but not visible from Eclipse (only from my file system explorer). – cellepo Oct 13 '15 at 23:12
-
I think "You would need to add gwt-user.jar and gwt-dev.jarto your projects build path" is the same as adding GWT SDK to the project build path (as the SDK contains those jars)? I'm not sure, because I had the SDK, but I still had to manually add those jars to WEB-INF/lib to prevent "Error: Could not find or load main class com.google.gwt.dev.Compiler" – cellepo Oct 13 '15 at 23:22
-
FYI: Ant seems to not like space chars in paths on Windows. So I had to move my eclipse from C:/.../Program Files to C:/ – cellepo Oct 13 '15 at 23:34
-
I think "(Edit `YourProject.EntryPointClass to the path to your EntryPoint-class)" should be "(Edit `YourProject.EntryPointClass to the path to your .gwt.xml module file)". – cellepo Oct 26 '15 at 22:16
Using Eclipse:
right click the project
choose Google→GWT Compile
when compilation has finished, the console will say i.e.
Linking into /home/janus/bpworkspace/gwtwerkstatt2/war/gwtwerkstatt2
Link succeeded
Compilation succeeded -- 28.623s
open a terminal and navigate to the directory
create the WAR:
jar cv * > /tmp/myGWTproject.war
you can now launch it with jetty-runner or similar:
java -jar jetty-runner-8.1.7.v20120910.jar /tmp/myGWTproject.war

- 1
- 1

- 20,267
- 14
- 135
- 196
-
2Note to anybody stumbling across this answer like I just did: you have to do "jar cvf YourWar.war ." from the war directory, not the directory that's linked into during step 3. – Kevin Workman Oct 28 '14 at 17:23
-
If you project has any project dependencies, you may also have to compile them and put the .jar files into the war/WEB-INF/lib folder before creating the .war file. You have to repeat this anytime they're updated. – thomas88wp Sep 29 '16 at 18:21
I just found this solution, and it's amazing :) Just install the jar and enjoy extracting to a war file.
Project Site http://code.google.com/p/gwt-project-export-wizard/

- 789
- 1
- 12
- 21
One can also use webAppCreator to generate Ant build file.
webAppCreator ships with GWT SDK and also with Eclipse GWT Plugin. First locate GWT plugin directory
find $HOME/.eclipse/ -name "*gwt*sdk*"
this will output GWT plugin dir path. This dir has gwt dir something like gwt-2.4.0. WebAppCreator will be in this dir. Set this dir as GWTSDK_HOME.
export GWTSDK_HOME=/home/m/.eclipse/org.eclipse.platform_3.7.0_1364963873/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201201120043-rel-r37/gwt-2.4.0
make webAppCreator executable
chmod 755 $GWTSDK_HOME/webAppCreator
Now create a project using webAppCreator in some temp dir.
$GWTSDK_HOME/webAppCreator -out fins in.m.fins.Fins
in.m.fins.Fins is the module name. This has to match with your project's gwt.xml in Eclipse workspace. If your gwt.xml is src/in/m/fins/Fins.gwt.xml then module name should be in.m.fins.Fins
-out fins will create the project and build.xml in fins directory. Copy generated build.xml file to your project in Eclipse workspace.
Run war target in Eclipse Ant Window to package your project as war

- 965
- 12
- 21
You have to have GWT designer installed from here
- In Eclipse on the main panel click on "Deploy module on aplication server" (It's next to blue google button).
- Chose war file name and location where to store it
- Click ok
That's it. Works on my GWT 2.4.0, Google Plugin for Eclipse 4.2, Eclipse Juno

- 444
- 1
- 7
- 21
Fist compile your project. Then: 1. Open your project. 2. Navigate to war folder. 3. Go to File>Export>Archive File 4. Export your war FOLDER as zip file. 5. Change your file extension form .zip to .war 6. Keep calm and enjoy your war file.

- 5
- 3
For future reference: you'll find another tutorial on how to create a .war using Eclipse on http://blog.elitecoderz.net/.

- 14,009
- 6
- 68
- 85
Compile your project. Then:
- Open your project.
- Navigate to war folder.
- Go to File>Export>Archive File
- Export your war FOLDER as zip file.
- Change your file extension form .zip to .war
- Keep calm and enjoy your war file.

- 5
- 3
-
I don't think that this is what the Op asked for even though the question might suggest it. – Xaver Kapeller May 04 '14 at 21:17