Java Servlet & JSP Cookbook
Authors: Perry B.W.
Published year: 2004
Pages: 28-29/326
Buy this book on amazon.com >>

Recipe 2.7 Deploying a Web Application on WebLogic Using Ant

Problem

You want to deploy a web application on WebLogic Server 7.0 using Jakarta Ant.

Solution

Create a Jakarta Ant build file. Ant can automatically compile your servlet classes, create a web-application archive ( .war ) file, and then deploy the WAR to WebLogic Server 7.0.

Discussion

You can either manually cut and paste web components into the WebLogic applications directory (as described in the sidebar), or use Ant to automate the process of compiling, generating a WAR file, and copying the WAR to this directory. An example directory path to applications is k:\bea\user_projects\bwpdomain\applications . This method would entail a minor edit of the build.xml and build.properties files described in Recipe 2.6.

Manually Deploying a Web Application

When BEA WebLogic Server 7.0 is running in development mode, if a WAR file, an enterprise archive application (EAR) file, or a directory that contains a valid web application is placed in the applications directory, then those applications are automatically deployed and become available on the server.

A valid web application contains a WEB-INF/web.xml deployment descriptor that does not generate any parsing exceptions. If the directory that you place in the applications folder does not contain a deployment descriptor, then WebLogic will not automatically deploy the application, even if the server is running in development mode. WebLogic raises an exception similar to this one in the console in which the server was started up:

<Unable to activate application, _appsdir_dist_dir, from source, K:\bea\user_
projects\bwpdomain\applications\dist. Reason: No J2EE deployment descriptor 
found at "K:\bea\user_projects\bwpdomain\applications\dist".>

This deploy-application Ant target is edited in build.xml to deploy on WebLogic 7.0:

<target name="deploy-application" depends="prepare" 
     description="Compile the web application....">
     <echo message="Compiling the application files..."/>
     <javac srcdir="$" destdir="$">
        <include name="*.java" />  
        <classpath refid="classpath"/>
     </javac>
     <echo message="creating the WAR file...."/>
     <antcall target="create-war"/>
     <copy todir="${wl.applications}">
        <fileset dir="$" />
     </copy>
 </target>

In addition, the build.properties file could define the wl.applications property with a value such as "k:\bea\user_projects\bwpdomain\applications". Once the WAR file is copied to this special directory, a WebLogic server that is started in development mode will automatically deploy it.

In the \user_project\bwpdomain directory (depending on your server domain name) the WebLogic start script is called startWebLogic.cmd on Windows and startWebLogic.sh on Unix. To start the server in development mode, the line in the start script should be set STARTMODE= (the value is an empty string here) or set STARTMODE=false . The server starts in production mode if it is set STARTMODE=true .


See Also

Recipe 2.3; Recipe 2.8-Recipe 2.10; WebLogic's Server 7.0 programmer documentation: http://e-docs.bea.com/wls/docs70/programming.html.


Recipe 2.8 Using the WebLogic Administration Console

Problem

You want to deploy a web application using WebLogic's Administration Console.

Solution

Bring up the Administration Console in your web browser and use its graphical interface to deploy either a WAR file or a web-application directory.

Discussion

The WebLogic Administration Console is a servlet- and browser-based tool for managing WebLogic server resources and Java 2 Enterprise Edition (J2EE) applications. To use the Console, WebLogic Server must be running. First, request the URL http://localhost:7001/console (or whichever your server address and port is, as in http://<weblogic-server-address>:<port>/console ). Then enter your login name and password to gain entry to the browser-based tool. The resulting screen looks like Figure 2-6, with a hierarchical list of choices in the lefthand column and the current screen choice in the righthand column.

Figure 2-6. WebLogic Administration Console
figs/jsjc_0206.gif

In the left column, choose the name of your domain by clicking on the plus sign ( + ), which displays the domain's subnodes. The subnodes of the domain include Servers, Clusters, Machines, Network Channels, Deployments, Services, and Security. Then choose the "Deployments" node, which gives you the choice of selecting its "Web Applications" subnode. Open up the "Web Applications" node by clicking on its plus sign. The resulting screen looks like Figure 2-7.

Figure 2-7. Web Applications node
figs/jsjc_0207.gif

In the Web Applications window, click the "Configure a New Web Application . . . " hyperlink. The next screen gives you the option of uploading the Web Application Archive (WAR) or Enterprise Application Archive (EAR) file through your browser to the server's filesystem, as shown in Figure 2-8.

Figure 2-8. Deploying a web application as a WAR or EAR file
figs/jsjc_0208.gif

Initiate this upload and then click on the "select" link next to the WAR file. Complete the three steps that Figure Figure 2-9 shows: click the arrow buttons to deploy the application from the "Available Servers" column to the "Target Servers" column, name the application (leave the name the same as the WAR filename minus the .war suffix), then press the "Configure and Deploy" button. That is all it takes to deploy the WAR file to the target server.

Figure 2-9. Final steps for deploying the WAR file
figs/jsjc_0209.gif

Now test the deployment by requesting one of the servlets in the browser, using the name that you gave the application as the context path . An example URL is http://localhost:7001/cookbook/cookieservlet . This URL requests a servlet that has been mapped to the name "/cookieservlet." The web-application context path is /cookbook .

Redeploying a previously undeployed web application using the WebLogic Administration Console involves the following steps:

  1. Select the name of your application under the Web Applications node in the Console's lefthand column. This shows a screen similar to Figure 2-10.

Figure 2-10. Selecting a web application in the Console
figs/jsjc_0210.gif
  1. Click the "Deploy" button in the righthand screen. This reactivates the application, so that it can receive requests in the WebLogic web container.

If you want to delete a web application using the WebLogic Administration Console, click on the name of your domain in the lefthand column of the Console screen, then on the "Deployments" and "Web Applications" nodes. Clicking the trash can icon associated with the application, as shown in Figure 2-11, deletes the application from the WebLogic server.

Figure 2-11. Deleting a web application
figs/jsjc_0211.gif

Deleting a web application in this manner means that the application is no longer available to receive requests in the WebLogic web container.

See Also

Recipe 2.3 and Recipe 2.7; Recipe 2.9 and Recipe 2.10; WebLogic's Server 7.0 programmer documentation: http://e-docs.bea.com/wls/docs70/programming.html.

Java Servlet & JSP Cookbook
Authors: Perry B.W.
Published year: 2004
Pages: 28-29/326
Buy this book on amazon.com >>

Similar books on Amazon