Servlet WAR File Weblogic Creation Deployment

Servlet WAR File Weblogic Creation Deployment

Servlet WAR File Weblogic Creation, Deployment and Execution is shown step-by-step for a Beginner.

With the release of the Java Servlet Specification 2.2, the concept of a Web application was introduced. According to this specification, a "Web Application is a collection of servlets, html pages, classes, and other resources that can be bundled and run on multiple containers from multiple vendors". That is, a Web application is anything that resides in the Web layer of an application.

One of the main characteristics of a Web application is its relationship to the ServletContext. Each Web application has one and only one ServletContext. This relationship is controlled by the Servlet container and guarantees that web applications will not clash when storing objects in the ServletContext.

The following items can exist in a web application:

  • Servlets
  • JavaServer Pages
  • Utility Classes
  • Static Documents including, XHTML, images, etc.
  • Client side classes
  • Meta information that describes the web application

The standard method for packaging Web applications is to use a Web ARchive file (WAR). You can create a WAR file by using Java’s archiving tool jar (jar command). The extension must be .war

Creating a WAR file (Step 1: Servlet WAR File Weblogic)

Suppose your current directory is greetings as: c:\snr\greetings>

greetings is a folder that contains all the files required for a WAR file. A WAR file should contain all the files to make it to work independently as one unit.

  1. Place all HTML and JSP files in it (in greeting directory).
  2. Create a WEB-INF directory under greetings directory and place web.xml file in it. You can copy the weblogic web.xml into it and remove the unwanted tags and keep only the tags required for your application.
  3. Create classes directory under WEB-INF directory and copy all the servlet’s .class files, your application needs.
  4. Now create the WAR file as follows:

    c:\snr\greetings> jar -cvf wishes.war *

    Asterisk, * indicates to include all the files and subdirectories of greetings folder.

    Now by name a file wishes.war file is created.

  5. Deployment (Step 2: Servlet WAR File Weblogic)
  6. Copy wishes.war into Weblogic’s (of Weblogic 8.1 version) applications directory available as follows:

    C:\bea\weblogic81\samples\domains\examples\applications

  7. Now run the weblogic server and type from the browser prompt as follows:
    Execution (Step 3: Servlet WAR File Weblogic)

    http://localhost:7001/wishes/myData

    where myData is the url-pattern name of the servlet written in your web.xml file. Remember this servlet file is in the classes directly of your Web application. 7001 is the port number on which Weblogic server is running.

A similar program is available but creating WAR file in Tomcat server WAR File in Tomcat with Creation, Deployment, Execution.

Leave a Reply

Your email address will not be published. Required fields are marked *