Home > Articles > Programming > Java

  • Print
  • + Share This

Deploying Your First Web Application Using the WebLogic Builder

This section showcases ways you can create, package, assemble, and deploy a simple Web application using the WebLogic Builder. Because this may be your first J2EE Web application, details of each step are discussed briefly. However, there is a detailed discussion of deploying Web and Enterprise applications to the WebLogic Server in Chapter 6, "Packaging, Assembling, and Deploying J2EE Applications."

A typical Web application is composed of the following elements:

  • One or more J2EE Web components such as servlets and Java Server Pages (JSPs).

  • Application resources such as JSP tag libraries, HTML pages, and image files.

  • An application-specific XML-based deployment descriptor file named web.xml, which lists your application's J2EE components and their configurations as J2EE modules. Each J2EE module is a collection of one or more J2EE components of the same container type (Web or EJB) that are represented by one component deployment descriptor for that type in the web.xml file.

  • A WebLogic-specific deployment descriptor file named weblogic.xml, which defines how named resources in the web.xml file are mapped to WebLogic Server resources. Examples of weblogic.xml attributes include HTTP session parameters, HTTP cookie parameters, JSP parameters, resource references, security role assignments, and container attributes.

The HelloWorldApp example described in the following sections is composed of a Welcome HTML page and a servlet, which returns a Hello World HTML page to your Web browser upon invocation. You will use the WebLogic Builder to generate the application deployment descriptors (web.xml and weblogic.xml) and then assemble the application resources into an exploded directory format, which will then be deployed to the WebLogic Server.

Follow the steps described in these sections to create, package, assemble, and deploy your first Web application to the WebLogic Server.

Step 1: Creating the Web Application Directory Structure

All J2EE Web applications use a standard hierarchical directory structure to maintain their application resources (servlets, classes, static files, and other resources). This directory structure is described in Table 3.2.

Table 3.2 The Hierarchical Directory Structure of a Web Application




The root directory of your Web application is known as the document root. This is the location where you will place all your static content files, such as HTML and Java Server Pages, which you want to be accessible to your client (Web browser).


The root of the WEB-INF directory is the location for the web.xml and weblogic.xml deployment descriptors. All files and directories under the WEB-INF directory are considered private and accessible only to the WebLogic Server.

(The WEB-INF directory name needs to be uppercase.)


The directory location for all server-side Java class files.


The directory location for JAR files.

The directory structure described in Table 3.2 complies with the J2EE specification and provides the foundation to assemble and deploy your Web application with any one of the following methods:

  • Creating a 1WAR archive file of the contents of the document root directory, including all subdirectories. This deployment format allows you to deploy the Web application from a remote machine directly to the Administration Server, which can then propagate the Web application as a WAR file to any of its Managed Servers.

  • Deploying the Web application as a collection of class files directly from the Web application directory. This type of deployment is known as the exploded directory format of deployment and requires the Web application directory to exist on the same machine as the target Administration Server. This is the method you will use to deploy your Web application.

WebLogic provides a default Web applications directory named applications, which you can find under your WebLogic Server domain directory. For the purposes of following this example, create a directory structure as specified in Table 3.2, using the name HelloWorldApp as your document root. Your HelloWorldApp application directory should resemble Figure 3.8.

Figure 3.8Figure 3.8 Your HelloWorldApp application directory.

Step 2: Creating Your Welcome Page

Typically, a Web application contains a Welcome page as an entry point to a Web application. Even though this example is relatively simple, you can create a Welcome page to call the servlet you will create shortly.

Use the following HTML to create your Welcome page and save the HTML file as index.html in the root of your HelloWorldApp directory:

<title>Welcome to my HelloWorldApp</title>
<p> This is the default welcome page for this example.
<p> <a href="./MyServlet">Click here</a> to call the Hello World servlet.

Step 3: Creating and Compiling Your Hello World Servlet

A complete discussion of servlets is outside the scope of this book. However, for the purposes of this example, follow these steps to create and compile a servlet named MyServlet, which is part of a package named objectmind.servlets:

  1. Open a text editor and enter the following Java code:

    package objectmind.servlets;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class MyServlet extends HttpServlet {
     public void service(HttpServletRequest req,
          HttpServletResponse res)
      throws IOException
     PrintWriter out = res.getWriter();
     out.println("<html><head><title>" +
        "Hello World!</title></head>");
     out.println("<body><h1>Hello World!</h1></body></html>");
  2. Save the Java code as a file named MyServlet.java in the root of your HelloWorldApp directory.

  3. From the command line, change the directory to your HelloWorldApp directory and set up your Java environment by invoking the setEnv script.

  4. From the command line in your HelloWorldApp directory, compile the MyServlet.java file using the following javac syntax:

    javac -d WEB-INF/classes MyServlet.java
  5. This command creates the MyServlet.class file in a directory structure under the Web-INF/classes directory according to the package name.

Step 4: Starting the WebLogic Builder

Now that you have created your J2EE components and HTML files, it is time to start using the WebLogic Builder to assemble and deploy your Web application.

Start the WebLogic Builder by choosing Start, Programs, BEA WebLogic Platform 7.0, WebLogic Server 7.0, WebLogic Builder.

Alternatively, you can start the WebLogic Builder from the command line by using the following command:


After the WebLogic Builder is launched, choose File, Open. From the dialog box, you can select an exploded or archived J2EE module. For this example, you have so far partially created an exploded Web application. Hence, select the HelloWorldApp directory, as shown in Figure 3.9, and click Open.

Figure 3.9Figure 3.9 Select your Web application using the WebLogic Builder.

After you click Open, the WebLogic Builder tries to locate and read any deployment descriptors associated with the J2EE module that you have selected to open. Because you have not created any deployment descriptors yet, the WebLogic Builder prompts you to allow it to search for Web modules or classes in your application directory and create the deployment descriptors for you, as shown in Figure 3.10. Click Yes.

Figure 3.10Figure 3.10 The WebLogic Builder's no deployment descriptor prompt.

When you open the HelloWorldApp module in the WebLogic Builder, you see a screen similar to Figure 3.11.

Figure 3.11Figure 3.11 The WebLogic Builder screen.

The WebLogic Builder screen is divided into the following panes:

  • The left pane is a hierarchical tree representation of the J2EE module you have opened. You can use this pane to explore and select the components of your Web application.

  • The right pane consists of tabbed panels with fields and other controls for editing the deployment descriptor elements of the J2EE module.

  • The bottom pane is activated through the View menu. You can use this pane to see information and error messages generated by the WebLogic Builder during the opening, creation, or deployment of a J2EE module.

The WebLogic Builder does its best in ensuring the values assigned to the deployment descriptor elements in the web.xml and weblogic.xml files are correct. However, because they are auto-generated, often you will need to create, modify, or delete certain deployment descriptor elements.

You can edit the deployment descriptors using the WebLogic Builder, or you can directly edit the web.xml and weblogic.xml files using an XML editor, such as the BEA XML Editor. In this example, you will edit the deployment descriptor files using the WebLogic Builder.

Because you have just created your deployment descriptors, to physically save them to your WEB-INF directory, you need to save your J2EE module. After you complete this save operation, you will see the web.xml and weblogic.xml files in the root of your WEB-INF directory.

Step 5: Assembling the HelloWorldApp Web Application

Up to now, you have partially created the HelloWorldApp Web application. The next step is to assemble the components of the application (servlets and HTML pages) so they are reflected in the deployment descriptors as one Web application. Follow these steps to assemble your HelloWorldApp application:

  1. Because you have created a Welcome page named index.html, you need to specify it in the WebLogic Builder. Select the HelloWorldApp identifier in the left pane, and in the corresponding Welcome Files tab, remove the index.jsp and index.htm files so that the index.html file is explicitly stated as the Welcome page, as illustrated in Figure 3.12.

Figure 3.12Figure 3.12 Assign the Welcome page.

  1. So far, the MyServlet servlet has only been compiled and placed into an appropriate directory structure under the WEB-INF directory. When you allowed the WebLogic Builder to create the deployment descriptors, it should have automatically discovered your MyServlet servlet and added an entry to the Web.xml file as a J2EE component of your Web application.

    To ensure this procedure occurred and the appropriate entries were specified as default by the WebLogic Builder, select the Servlets folder in the left pane. If the MyServlet node exists, select it and ensure the following information is specified correctly, as illustrated in Figure 3.13.

    • Servlet Name= MyServlet

    • Server Class = objectmind.servlets.MyServlet

    • URL Mappings = /MyServlet/*

    If the MyServlet servlet has not been discovered by the WebLogic Builder, click Add in the corresponding right pane. This operation launches a window for you to add the preceding information.

    The URL Mapping allows you to call the servlet directly from a Web browser after the Web application is deployed, thus allowing you to test the operation of a servlet. After you validate or enter your MyServlet information, click OK.

Figure 3.13Figure 3.13   Configure the MyServlet servlet deployment descriptor information.

  1. Now save your deployment descriptors by choosing File, Save. Your simple HelloWorldApp application is now assembled and ready to be deployed.

Step 6: Deploying Your Web Application

You have two options for deploying your HelloWorldApp application. Either you can create a WAR archive file of the entire contents of the HelloWorldApp directory, or you can deploy your application directly from the HelloWorldApp directory as long as the target Administration Server is hosted locally. This exploded directory deployment is possible because the web.xml and weblogic.xml deployment descriptors have been created and edited to reflect the J2EE components and other files that constitute your Web application.


If you have enabled WebLogic autodeployment using -Dweblogic.ProductionModeEnabled=false, your application will automatically be deployed. However, the .jar, .war, and .ear files of the exploded directory must be contained within the applications directory.

The difference between these two deployment methods in the WebLogic Builder is that in an exploded directory deployment, the name of the Web application is stated by the name of the document root directory, which in this case is HelloWorldApp. In the WAR archive deployment method, the name of the Web application is governed by the name you assign to the WAR archive file, and you can deploy the Web application to a remote Administration Server.

The following steps will guide you through the deployment procedures for your exploded directory Web application:

  1. Connect to the target WebLogic Administration Server by choosing Tools, Connect to Server. In the launched dialog box, enter your specific WebLogic connection information, as shown in Figure 3.14, and click Connect.

Figure 3.14Figure 3.14   Connect to the WebLogic Server.

  1. To deploy your Web application, select Tools, Deploy Module. From the launched Deploy screen, as shown in Figure 3.15, click Deploy to initiate deployment of your HelloWorldApp application to the WebLogic Server.

Figure 3.15Figure 3.15 Deploying HelloWorldApp using the WebLogic Builder.

To validate your application has been deployed, you can open the Deploy screen by choosing Tools, Deploy Module and clicking the Manage Deployments tab. Here, you can validate the status of your Web application on the WebLogic Server. If it does not appear to be deployed, highlight your HelloWorldApp application and click Deploy.

Step 7: Testing Your Web Application

You can test your Web application by typing the following URL in your Web browser:


where machine_name specifies your WebLogic Server's DNS name or IP address. This URL should launch your Welcome page, as shown in Figure 3.16.

Figure 3.16Figure 3.16 The Welcome page of your HelloWorldApp application.

Click the Click here link to invoke your MyServlet servlet to display the Hello World! HTML page. Alternatively, you can invoke it by using the following URL:

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.