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:

right_click_src

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

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

popup_export

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

2) The following PopUp-menu will appear.

Select “Export …” from this menu.

Select_export_format

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

3) Select “JAR file” from the next window

select_export_source_and_target

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" />
			</webinf>
		</war>
	</target>
 
	<target name="deploy">
		<copy file="<projectname>.war" todir="." />
	</target>
 
</project>

run_ant_script

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. 02:32 PM at 02:32 PM | #1

    thanks !! works well

  2. Mikel
    03:51 PM at 03:51 PM | #2

    Hey,

    absolutely perfect; this is what i would like to call “missing manual” for GWT-Deployment!

    Thank you so much!

    Mikel from Germany

  3. Nikhil Dhavale
    09:52 AM at 09:52 AM | #3

    I mean how to deploy it on tomcat . Any command line commands for the same

  4. 10:45 AM at 10:45 AM | #4

    @Nikhil Dhavale: After running the ant-script, you have to deploy the generated .war to your tomcat, using the default-upload service of your tomcat-manager. If you have no access to the tomcat-manager, you can also directly copy the file into the “webapps”-folder of your tomcat.

  5. Robert
    09:34 AM at 09:34 AM | #5

    Thanks a lot, it’s working fine.

  6. andy christianson
    08:01 PM at 08:01 PM | #6

    I can confirm this works as well. Thanks!

  7. Tiago Megas
    03:31 PM at 03:31 PM | #7

    You are the man o/

    Thanks for the help!

  1. No trackbacks yet.