GWT - DEPLOY APPLICATIONThis tutorial will explain you how to create an application “war” file and how to deploy that in Apache Tomcat Websever root. If you understood this simple example, then you will also be able to deploy a complex GWT application following similar steps. Now, let us have a working Eclipse IDE along with GWT plugin place and follow certain steps to create a GWT application:
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='helloworld'> <!-- Inherit the core Web Toolkit stuff. --> <inherits name='com.google.gwt.user.User'/> <!-- Inherit the default GWT style sheet. --> <inherits name='com.google.gwt.user.theme.clean.Clean'/> <!-- Specify the app entry point class. --> <entry-point class='com.jtc.client.HelloWorld'/> <!-- Specify the paths for translatable code --> <source path='client'/> <source path='shared'/> </module> Following is the content of the modified Style Sheet file war/HelloWorld.css.
body {
text-align: center; font-family: verdana, sans-serif; } h1 { font-size: 2em; font-weight: bold; color: #777777; margin: 40px 0px 70px; text-align: center; } Following is the content of the modified HTML host file war/HelloWorld.html.
<html>
<head> <title>Hello World</title> <link rel="stylesheet" href="HelloWorld.css"/> <script language="javascript" src="helloworld/helloworld.nocache.js"> </script> </head> <body> <h1>Hello World</h1> <div id="gwtContainer"></div> </body> </html> I modified the HTML a little bit from the previous example. Here I created a placeholder <div>...</div> where we will insert some content using our entry point java class. So let us have the following content of Java file src/com.jtc/HelloWorld.java.
package com.jtc.client;
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.RootPanel; public class HelloWorld implements EntryPoint { public void onModuleLoad() { HTML html = new HTML("<p>Welcome to GWT application</p>"); RootPanel.get("gwtContainer").add(html); } } Here we created a basic widget HTML and added it inside the div tag having the id="gwtContainer". We will study different GWT widgets in the coming chapters. Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, then this will produce the following result: Create WAR File Now our application is working fine and we are ready to export it as a war file. Follow the following steps:
Enter a url in the web browser: http://localhost:8080/HelloWorld to launch the application. Server name (localhost) and port (8080) may vary as per your tomcat configuration. |