SyntaxHighlighter

Friday, December 14, 2012

Deployment Plan - How does it works in Weblogic ?

Overview:
In JavaEE world, The most commonly used application packages are Java Archive (jar) , Web Archive (war) or Enterprise Archive (ear). For the application servers to deploy JavaEE application using above packages, standard rules (based on the archive option) needs to be followed to create folder structure to keep application specific java classes,dependent libraries or deployment descriptors etc...


Introduction:
Most commonly used deployment descriptor files are
  1. Web Archive -- WEB-INF/web.xml or weblogic.xml (optional).
  2. Java Archive  -- META-INF/ejb-jar.xml and weblogic-ejb-jar.xml
  3. Enterprise Archive --- META-INF/application.xml.
Through deployment descriptors, developers describes their application informations and provides instructions to application server to deploy them accordingly.

What if your application is deployed in production and you run into few possible situations as below:
  1. change Context-root in application.xml file
  2. Servlet mapping or class is incorrect in web.xml
  3. Ejb Class Name has typo in ejb-jar.xml
  4. increase or decrease bean pool size based on load in weblogic-ejb-jar.xml
  5. JNDI name is incorrectly supplied in weblogic-ejb-jar.xml
  6. increase Transaction time-out in weblogic-ejb-jar.xml.
  7. Any possible unknown situation.
Unfortunately, all above informations are bundled inside the package archive, so it involves change , build , redeployment or emergency release (if critical).

Thanks for JSR-88. Fortunately all Java EE application servers provides an implementation to JSR-88 and let you change your application behavior at runtime without modifying any deployment descriptor and rebuilding your application package, which is called as a "Deployment Plan".

To understand it better, we will take hypothetical example as below (which can rarely happen)
Below EJB is
  1. bundled in Java Archive (jar)
  2. deployment descriptor are supplied under META-INF/ejb-jar.xml and META-INF/weblogic-ejb-jar.xml.
  3. application is deployed as an Enterprise Archive (ear).
Sample EJB Code:

package com.test.ejb.dummy;

import javax.ejb.Stateless;

@Stateless
public class DummyEJB {
 public void doDummyThings(){
  System.out.println("Do Dummy things");
 }
}
Sample ejb-jar.xml file (Intentionally Used Wrong EJB-CLASS Name)

Once we deploy EAR file using wrong EJB class, application fails to deploy and complaints as below






Deployment Plan comes to the rescue:

How does Deployment Plan works ?

Deployment plan is nothing but a special XML file which can be prepared to instruct application server to use along with the package archive and informations in plan xml file overrides one specified in deployment descriptor.

Prepare plan XML file and give it a name. Plan XML file should contain the informations we want to override at runtime. In our case, its a ejb-class name.


Save plan xml file at some location on the same machine where application server is running.

Log into administration console ---> Deployment

Click on "Change Path" button and navigate to the file where you have saved plan.xml file.


Select redeploy and finish


Now, application server will redeploy the application using "Deployment Plan" we specified.Once its done, we will see application is deployed successfully.

Just to make sure, what is the EJB class being used, click on EJB Module and Configuration you will see as below.



What if we are NOT allowed to redeploy via console ?

No worry, weblogic.Deployer command is the way to GO then:

java weblogic.Deployer -adminurl t3://localhost:7001 -username weblogic -password weblogic123
-redeploy -name testRide -plan C:\Rajesh\Others\PLAN\testRidePlan.xml


Hope it helps.


1 comment:

  1. This is really helpful for me . Thanks alot

    ReplyDelete