Thursday, December 24, 2009

ADF 11: Create Application EAR for test and production deployment respectivly

Status: resolved
Oracle JDeveloper Deploy: 11.1.1.2.0.5536

In this post I want to show how you can easily automate the issue mentioned in Andrejus Baranovskis post about How to do Manual Deployment for ADF 11g Application EAR with Auto Generated JDBC Descriptors.

Introduction

Ok, so what actually is the issue with the Auto Generated JDBC Descriptors in the generated EAR? To understand the problem better I have made up a quick overview

image

You see a typical scenario of a development environment (not optimal but no that bad) On each developers machine there is JDeveloper and the Integrated WebLogic Server installed. If a developer joins a project she checks out the sourcecode, opens it Jdeveloper and is able to run the application. It order to get this working JDeveloper generates the appropriate JDBC descriptors and packages the datasource definition into the EAR which is deployed on the integrated WLS. The application runs on developers machine with zero configuration changes because ‘Auto-generate and Synchronize weblogic-jdbc.xml Descriptors During Deployment' checkbox on the Deployment page of the workspace's Application Properties dialog is activated.

On the right side you see the components on the test/nightly build server with dedicated test database! So the connection information is different from the dev system, the data source in  the WLS must be created manually or script based. For that reason the EAR must not include any datasource definitions because they are obtained from the container (WLS). The EAR is generated by the ojdeploy utility which operates mainly on the application workspace file (.jws)

The problem now is that the ‘Auto-generate and Synchronize weblogic-jdbc.xml Descriptors During Deployment' option is saved in the Application Workspaces file which resides in the SCM repository and both - the developer and Test-Server - obtain there config from a single source!

Solution

Is simple, works but maybe a bit dirty;-) Observing the application workspace file (jws) I recognized the following line

<value n="Weblogic-JDBC-Auto-Sync-Key" v="true"/>

So  switching the value to false before running ojdeploy should do the trick. I have done this with Ant. Create the following files into your workspace

image

as follows

deploy_to_ear.ant.properties
oracle.jdeveloper.workspace.path=C\:\pathto\YourApp.jws
autosync.true=<value n="Weblogic-JDBC-Auto-Sync-Key" v="true"/>
autosync.false=<value n="Weblogic-JDBC-Auto-Sync-Key" v="false"/>

deploy_to_ear.ant.xml
<?xml version="1.0" encoding="windows-1252" ?>
<project name="Deploy Helper Tasks" default="usage" basedir=".">
  <property file="deploy_to_ear.ant.properties"/>
  <target name="usage">
    <echo>Use one of the following targets:</echo>
    <echo>1) disable-wls-jdbc-autosync - desc todo</echo>
    <echo>2) enable-wls-jdbc-autosync  - desc todo</echo>
  </target>
  <target name="disable-wls-jdbc-autosync">
    <replaceregexp match="${autosync.true}"
                   file="${oracle.jdeveloper.workspace.path}"
                   replace="${autosync.false}"/>
  </target>
  <target name="enable-wls-jdbc-autosync">
    <replaceregexp match="${autosync.false}"
                   file="${oracle.jdeveloper.workspace.path}"
                   replace="${autosync.true}"/>
  </target>
</project>

deploy_to_ear.ojdeploy.xml
<?xml version = '1.0' standalone = 'yes' ?>
<ojdeploy-build>
  <deploy>
    <parameter name="workspace" value="${workspace.path}\YourApp.jws"/>
    <parameter name="profile" value="*"/>
    <parameter name="nocompile" value="true"/>
    <parameter name="nodatasources" value="true"/>
    <parameter name="forcerewrite" value="true"/>
    <parameter name="outputfile" value="${workspace.path}/deploy/${ear.filename}"/>
  </deploy>
</ojdeploy-build>

deploy_to_ear.bat
@echo off

echo [INFO] Create deployment EAR for ADF fusion web application

call ant -f deploy_to_ear.ant.xml disable-wls-jdbc-autosync
call ojdeploy -buildfile deploy_to_ear.ojdeploy.xml -define workspace.path=C:\yourpath\to\workspace,ear.filename=testapp1_without_datasources.ear
call ant -f deploy_to_ear.ant.xml enable-wls-jdbc-autosync

Alternatively to run the enable-wls-jdbc-autosync target after ojdeploy has finished you could also do a revert on the .jws file if your SCM system supports it.

In my sample application the generated EAR files look as follows

image

Keep on automating your build process;-)

No comments:

Post a Comment