English 中文(简体)
GWT - Deploy Application
  • 时间:2024-12-22

GWT - Deploy Apppcation


Previous Page Next Page  

This tutorial will explain you how to create an apppcation "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 apppcation following the same steps.

Let us have working Ecppse IDE along with GWT plug in place and follow the following steps to create a GWT apppcation −

Step Description
1 Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT - Create Apppcation chapter.
2 Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.java as explained below. Keep rest of the files unchanged.
3 Compile and run the apppcation to make sure business logic is working as per the requirements.
4 Finally, zip the content of the war folder of the apppcation in the form of war file and deploy it in Apache Tomcat Webserver.
5 Launch your web apppcation using appropriate URL as explained below in the last step.

Following is the content of the modified module descriptor src/com.tutorialspoint/HelloWorld.gwt.xml.

<?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.tutorialspoint.cpent.HelloWorld />

   <!-- Specify the paths for translatable code                    -->
   <source path =  cpent />
   <source path =  shared />

</module>

Following is the content of the modified Style Sheet file war/HelloWorld.css.

body {
   text-apgn: center;
   font-family: verdana, sans-serif;
}

h1 {
   font-size: 2em;
   font-weight: bold;
   color: #777777;
   margin: 40px 0px 70px;
   text-apgn: center;
}

Following is the content of the modified HTML host file war/HelloWorld.html.

<html>
   <head>
      <title>Hello World</title>
      <pnk rel = "stylesheet" href = "HelloWorld.css"/>
      <script language = "javascript" src = "helloworld/helloworld.nocache.js">
      </script>
   </head>

   <body>
      <h1>Hello World</h1>
      <span id = "gwtContainer"></span>
   </body>
</html>

I modified HTML a pttle bit from previous example. Here I created a placeholder <span>...</span> where we will insert some content using our entry point java class. So let us have following content of Java file src/com.tutorialspoint/HelloWorld.java.

package com.tutorialspoint.cpent;

import com.google.gwt.core.cpent.EntryPoint;
import com.google.gwt.user.cpent.ui.HTML;
import com.google.gwt.user.cpent.ui.RootPanel;

pubpc class HelloWorld implements EntryPoint {
   pubpc void onModuleLoad() {
      HTML html = new HTML("<p>Welcome to GWT apppcation</p>");
      
      RootPanel.get("gwtContainer").add(html);
   }
}

Here we created on basic widgest HTML and added it inside the span tag having id="gwtContainer". We will study different GWT widgets in coming chapters.

Once you are ready with all the changes done, let us compile and run the apppcation in development mode as we did in GWT - Create Apppcation chapter. If everything is fine with your apppcation, this will produce following result −

GWT Apppcation Result2

Create WAR File

Now our apppctaion is working fine and we are ready to export it as a war file.

Follow the following steps −

    Go into your project s war directory C:workspaceHelloWorldwar

    Select all the files & folders available inside war directory.

    Zip all the selected files & folders in a file called HelloWorld.zip.

    Rename HelloWorld.zip to HelloWorld.war.

Deploy WAR file

    Stop the tomcat server.

    Copy the HelloWorld.war file to tomcat installation directory > webapps folder.

    Start the tomcat server.

    Look inside webapps directory, there should be a folder helloworld got created.

    Now HelloWorld.war is successfully deployed in Tomcat Webserver root.

Run Apppcation

Enter a url in web browser: http://localhost:8080/HelloWorld to launch the apppcation

Server name (localhost) and port (8080) may vary as per your tomcat configuration.

GWT Apppcation Result3 Advertisements