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="${src}" destdir="${build}">         <include name="*.java" />           <classpath refid="classpath"/>      </javac>      <echo message="creating the WAR file...."/>      <antcall target="create-war"/>      <copy todir="${wl.applications}">         <fileset dir="${dist}" />      </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.



Java Servlet & JSP Cookbook
Java Servlet & JSP Cookbook
ISBN: 0596005725
EAN: 2147483647
Year: 2004
Pages: 326

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net