This was originally posted on my dev2dev blog August 30th, 2007.
One of my customers asked me about a common use case: they would like to change the value of a Java annotation in their deployment artifacts at deployment time without changing the code. This way they can avoid having separate EAR files for each environment. Using the same EAR file is very desirable because you know what you tested in QA is the same code that you are putting into production. I'd consider that a best practice.
In this case, assume we are using Beehive Service Control to invoke a web service. The URL of that service changes depending one each environment (dev, qa, prod). Since Beehive is heavily annotations based and the URL endpoint of the web service is actually put into code, how can we change that URL for the various environments without building a separate EAR file for each environment? The solution is a combination of deployment plans (JSR-88) and a Beehive annotation override. It turns out that Chris Hogue has already blogged this and his steps apply to 9.x and 10.x versions of WLS. His entry is very straight-forward, but I found that the WebLogic console interface was not as intuitive as Chris's post.. So I wrote up the steps I followed to get it working. These steps will create a plan.xml and the Beehive annotation-overrides.xml files for you,. Once you understand the mechanisms, you could script this and apply it to other WEB-INF or META-INF files and values that might change between environments and say goodbye to multiple EAR files.
Here's Chris description of the steps to follow after deploying your EAR to WLS:
Now say I've deployed it to the production server. After deploying it the first time I can go into the WLS console, locate the control, and change the value through a simple form. To find it in the console, navigate to Deployments > [your application] > Deployment Plan > Resource Dependencies. Then locate your control in the "Controls" tree to find the available settings. It should look something like this:
I suggest you read Chris's full entry, but I'm going to get a little more granular with the instructions.
For curiosity you can browse to the directory where your deployment plan is stored (you select the directory yourself). Your plan.xml will refer to an annotations-overrides.xml file, which you will find in the web application directory as META-INF/annotations-overrides.xml. Here's an example of mine. Notice the override-value where I switch to port 7001 instead of 7011. I hope this more detailed explanation of Chris's post helps avoid the hang-ups that I encountered.
<?xml version='1.0' encoding='UTF-8'?>
<annotation-overrides xmlns="http://www.bea.com/2004/03/wlw/external-config/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<component-type>Control Extension (JCX)</component-type>