Developing Web Applications
with OpenRules and WebLogic

Part 1 – Environment Setup and Basic WebLogic Application

This is the first part of a step-by-step account of how to setup an environment and develop a basic web application from scratch using WebLogic and OpenRules. This application and setup will be used as a starting point for different web application configurations using OpenRules and different application servers and development frameworks.

WebLogic Server Installation

The BEA WebLogic Server comes packaged with the WebLogic Platform distribution or as an individual distribution. For the purpose of this article, we will be downloading and installing the complete BEA WebLogic 8.1 platform distribution. You can download a copy of the BEA WebLogic Platform distribution with a 1 year development license from the BEA website: http://www.bea.com/. After downloading and installing the WebLogic Platform, you should have many directories including:

Directory

Contains

Default Location

BEA Home

This directory contains license files, the install JDK(s) and common files.

C:\bea

WebLogic Home

All of the WebLogic software packages and configuration files.

C:\bea\weblogic81

Run c:\bea\weblogic81\server\bin\startWLS.cmd. Answer questions concerning a user and a password and you will receive a file c:\bea\weblogic81\server\bin\startmydomain.cmd that will be used to start your WebLogic server.

Step 1 – development directory

We are going to need a place to keep all the source and other files we will be creating, so let's create a directory and name it 'hello.bea'. You can place this directory in your home folder or in some other location.  Inside this directory we create a 'src' directory to hold all Java source files. Then we create another directory that we name 'war'. This directory will hold everything that should go into the WAR file, that we would use to deploy our application. All source files other than Java source, like JSPs and configuration files, belongs in this directory.

Step 2 – index.jsp

We will start by creating a JSP page named 'index.jsp' in the war directory. This is the entry point for our application.

hello.bea/war/index.jsp
<html>
<head><title>Example :: Hello Web Application</title></head>
<body>
<h1>Example - Hello Application</h1>
<p>This is my test.</p>
</body>
</html>

Just to have a complete web application, we create a web.xml in a WEB-INF directory that we create under the war directory.

hello.bea/war/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'>

<web-app>

</web-app>

Step 3 – deploying the application to WebLogic

Next, we write an Ant build script that we are going to use throughout this document. There are tasks for building and deploying the application. A separate build script contains the app server specific tasks There are also tasks for controlling the application under BEA.

hello.bea/build.xml
<?xml version="1.0"?>

<project name="hello.bea" basedir="." default="usage">
<property file="build.properties"/>

<property name="src.dir" value="src"/>
<property name="web.dir" value="war"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="hello.bea"/>

<path id="master-classpath">
	<!-- <fileset dir="${web.dir}/WEB-INF/lib">
		<include name="*.jar"/>
	</fileset>
	-->
	<pathelement path="${build.dir}"/>
</path>

<target name="usage">
	<echo message=""/>
	<echo message="${name} build file"/>
	<echo message="-----------------------------------"/>
	<echo message=""/>
	<echo message="Available targets are:"/>
	<echo message=""/>
	<echo message="build --> Build the application"/>
	<echo message="deploy --> Deploy application as directory"/>
	<echo message=""/>
</target>

<target name="build" description="Compile main source tree java files">
	<mkdir dir="${build.dir}"/>
	<javac destdir="${build.dir}" target="1.2" source ="1.3" debug="true"
		deprecation="false" optimize="false" failonerror="true">
		<src path="${src.dir}"/>
		<classpath refid="master-classpath"/>
	</javac>
</target>


<target name="deploy" depends="build" description="Deploy application as a WAR file">
	<war destfile="${name}.war"
		webxml="${web.dir}/WEB-INF/web.xml">
	  <fileset dir="${web.dir}">
		<include name="**/*.*"/>
	  </fileset>
	</war>
	<copy todir="${deploy.path}" preservelastmodified="true">
	  <fileset dir=".">
		<include name="*.war"/>
	  </fileset>
	</copy>
</target>


</project>

This script now contains all the targets that we are going to need to make our development efforts easier. We are not going to cover this script in detail since most if not all of it is pretty much standard Ant and an application server stuff. You can just copy the above build file and put it at the root of your development directory tree. We also need a build.properties file that you should customize to match your server installation. This file belongs in the same directory as the build.xml file.
 

hello.bea/build.properties
# Ant properties for building the hello.bea

appserver.home=c:/bea/weblogic81/server/bin
deploy.path=${appserver.home}/applications

Now we run Ant target 'usage' to make sure that everything is working OK. You should have your current directory set to the 'hello.bea' directory.
 

Buildfile: build.xml
 
usage:
 
     [echo] helloapp build file
     [echo] -----------------------------------
 
     [echo] Available targets are:
 
     [echo] build     --> Build the application
     [echo] deploy    --> Deploy application as directory
 
BUILD SUCCESSFUL
Total time: 1 seconds

Last action here is to do the actual deployment. Just run Ant and specify 'deploy' as the target.


Buildfile: build.xml
 
build:
[mkdir] Created dir: /hello.bea/war/WEB-INF/classes

deploy: [war] Building war: /hello.bea/hello.bea.war
[copy] Copying 1 file to C:/bea/weblogic81/server/bin/applications
BUILD SUCCESSFUL
Total time: 844 milliseconds

Step 4 – Test the application

Now open a browser and browse to http://localhost:7001/hello.bea/


 

To simplify the future launches of a browser, we will add the following 'run.html' file to the project directory:


<h2> OpenRules </h2>
<h3> BEA-based Basic JSP Web Application</h3>
<ul>
<li>Business logic - Java</li>
<li>Views - JSP</li>
</ul>
<a href="http://localhost:7001/hello.bea/index.jsp"> 
Run Hello Customer Example</a>

 

Summary

  1. We created a development environment with Ant build files.

  2. We setup a trivial web application that is used only to test our setup.

  3. So far, our application hello.bea is extremely basic. But the whole setup works and we are now ready to add real functionality.

 

Back     Implementing HelloCustomer Application using JSP and Java

Copyright © 2005-2006, OpenRules, Inc.