Home > GWT > GWT and tomcat: Create .war using eclipse to deploy .war on tomcat

GWT and tomcat: Create .war using eclipse to deploy .war on tomcat

Howto compfortably build a correct .war from your GWT-project using eclipse to deploy it to a tomcat server.

There are only two simple steps to take, to build a .war from your GWT project:

Short version:

The first step is building a .jar from your src-folder and putting the .jar into the lib-folder of the .war-folder of your GWT-project. The second step is building a .war-file from your war-folder and deploying the .war to your tomcat server. To make the second step more compfortable, I wrote a little Ant-script, that will create the .war.

More detailed – Step 1:


1) Right-click your projects src-folder (click for larger view)

1) Right-click the src folder inside your project.


2) Select "Export" from the PopUp (click for larger view)

2) The following PopUp-menu will appear.

Select “Export …” from this menu.


3) Select "JAR File" as export-format (click for larger view)

3) Select “JAR file” from the next window


3) Select export source and target (click for larger view)

4) Make sure, only the “src”-folder of your project is checked in the next window.

Select the export destination like this: <folder of your project>/war/WEB-INF/lib/<projectname>.jar – then click “Finish”

Now your GWT-project is ready to be packed into a .war, that can be deployed to a tomcat server.

More detailed – Step 2:

1) Create a new ANT-script in your project (Right-click your project folder and select “New” and then select “File” from the submenu. Call the new file “warbuilder.xml” or something like this.).

2) Copy the following content into the newly created file. Replace <projectname> with the name of your project:

<project name="<projectname>" basedir="." default="default">
	<target name="default" depends="buildwar,deploy"></target>
	<target name="buildwar">
		<war basedir="war" destfile="
<projectname>.war" webxml="war/WEB-INF/web.xml">
			<exclude name="WEB-INF/**" />
			<webinf dir="war/WEB-INF/">
				<include name="**/*.jar" />
	<target name="deploy">
		<copy file="
<projectname>.war" todir="." />

5) Run the warbuilder ANT-script (click for larger view)

3) The first two steps must be done only once. You can reuse the warbuilder.xml and do not have to build it every time. Now simply right-click the “warbuilder.xml” and select “Run As” and “Ant Build” from the PopUp-menu.

The .war-File will be created by this ANT-script. You will find the .war-file in your ProjectFolder.

If you enjoyed this post, make sure you subscribe to my RSS feed!
Categories: GWT Tags: , , , , ,
  1. lee
    07:10 PM at 07:10 PM | #1

    To explain a little. You can skip creating the jar from the compiled source java files and copying that jar into web-inf/lib if you do a few alternate things.

    Before running the ant script, click the GWT suitcase looking icon that compiles the project. (It puts the class files in web-inf/classes.

    Add a line to the ant build xml just below where you include **/*.jar. It will look just like that line but the file name inside the quotes will be “classes/**”. (This adds the jar files from web-inf/lib and the class files from web-inf/classes.

    This is an alternate way to supply the java class files to run the back end of the application. Either building the jar and copying it in, as you described, OR doing the GWT compile and including the classes when building the war file. Either should work.

  2. Rafael
    08:31 PM at 08:31 PM | #2
  3. Nate
    11:37 PM at 11:37 PM | #3

    Thanks, it appears to be just what I’m looking for to test my new (and first) Tomcat installation. I’ll try it Monday.

    It appears that your script/application puts Time() at Time() in the message headers rather than Date() at Time().

    Therefor I have no idea if this is a thread is still live…

  4. Tarek
    09:34 AM at 09:34 AM | #4

    Thank you ! it work fine

  5. 05:35 AM at 05:35 AM | #5

    Good article Everything work fine but I have some problem.. when I open myPage.html it work fine but if I call my project by this url “localhost:8080/myProject/myPage.html”
    I found error 404 can someone solve my problem

    thanks for help. Nuttee From Thailand

  6. 09:24 AM at 09:24 AM | #6

    plz forget my problem.. i solution it by mapping servlet in web.xml

  7. phot0
    07:19 PM at 07:19 PM | #7

    Hi man,
    It looks really nice, but it’s not working here.
    I do everything as said and when I run on tomcat it doesn’t work.
    At chrome debugger it says:
    Failed to load resource: the server responded with a status of 404 (Not Found) :Project.css
    Failed to load resource: the server responded with a status of 404 (Not Found) :8080/Project/project/servlet?

    and the same for my other servlets

    Any Idea of how to make it work??

  8. Frank
    05:43 PM at 05:43 PM | #8

    Thank you!

  9. joe
    01:37 PM at 01:37 PM | #9

    It doesn’t seem like creating the .jar from the src folder is necessary. I’m not sure why it’s being done for deployment purposes? None of that code is compiled into either javascript or java. It seems like something that you would do if you were packaging everything into a jar file so that another module could inherit it and that other module would be able to run a debugger and see the source code.

  10. AngiSad
    09:01 PM at 09:01 PM | #10

    I followed your tutorial but I got the message “GWT module needs to be (re) compiled” once i try to access the app.
    Can you tell me what I missed plz?

  11. 11:41 PM at 11:41 PM | #11

    Good article. However when I try to build the ant file, I get library reference problems. This is the error message I get

    Main.java:6: package com.google.gwt.core.client does not exist
    [javac] import com.google.gwt.core.client.EntryPoint;

    When I compile this via development server, everything works fine and also I checked that the GWT SDK lives in classpath. Any ideas ?

  12. chai
    02:40 AM at 02:40 AM | #12

    thank , This article ‘s very helpful to me

  13. kkk
    08:23 AM at 08:23 AM | #13

    Cool! Thanks for post, it works very well.

  14. FongT Mr
    07:17 AM at 07:17 AM | #14

    This is unfortunately slightly bogus advice. There is absolutely no need to compile the src folder.

  15. Zach Jullion
    10:21 PM at 10:21 PM | #15

    Sir, thank you SO MUCH for this article! I have step the last three hours trying to get a GWT application using a Java Servlet to deploy properly and I believe you have solved my problem!

  16. churro
    09:43 PM at 09:43 PM | #16

    I know this comment is about 3 years too late, but GWT has a nice utility called “webAppCreator” that generates a build.xml. You can run it with the module name you want (eg: -out foo com.example.foo.Foo) and it will make a build.xml for you. So if you already have a project called “com.example.foo.Foo” you can use it to make yourself a build script.

  17. Shivendra
    10:21 AM at 10:21 AM | #17

    Superb article , this one really helped me to deploy my gwt application on tomcat . It hardly took me 10 mins on something for which I had wasted more than 2 days. Thanks a lot.

  18. CarlE
    08:53 PM at 08:53 PM | #18

    Allright Man! What a TIME savings… EXACTLY what I needed to solve the deployment to a tomcat instance.
    Thank you so much for the time you spent to help others out. You just generated GOOD karma from doing so.



  19. stanley
    03:08 AM at 03:08 AM | #19

    thank you so much this post has solved my problem. i am so happy
    may God bless everyone here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Comment pages
1 2 286
  1. 11:18 PM at 11:18 PM | #1
  2. 10:07 AM at 10:07 AM | #2