Wednesday, April 24, 2013

Weblogic Server Shared Library Implementation

In this post, we will see how to implement this weblogic’s Shared library concept . As part of this tutorial you will also learn the bundling part of the Shared Library like,

1] Bundling all related jars(Spring,Hibernate,MYSQL jars) to a single war
2] Create manifest file using ant and bundle this modified MANIFEST.MF

Scenario:

In a project we got a scenario like 5 different web applications which refers it’s own sets of library(Spring Jars,Hibernate Jars,MySQL jars,Logger Jars and etc ), see the below diagram for further reference.
Web Application referring it’s own set of Libraries:
image


We initially thought of bundling App1.war with it’s own set of libraries, App2.war with the same set of libraries and so.
Size of Web Application Bundled with it’s own set of Libraries:
Application Name Application Size
App1.war 160MB
App2.war 158MB
App3.war 161MB
App4.war 155MB

So we do not want to dump all the jar files into the application's war. It will render the war file to a huge sized one. Instead, of that we have separated the library files from applications and refer it at run time, as the following image.

image
Size of Web Application after the Shared Library Implementation:
So web application size is reduced enormously now, you could able see everything clearly right ?
Application Name Application Size
App1.war 10MB
App2.war 8MB
App3.war 11MB
App4.war 5MB

Implementation Part:

Step 1: Created a new Hudson Job to do the Bundling Part of Shared-lib Module
image
Step 2: We have bundled this Shared-lib module as a war file using build.xml
<war destfile="${dist.home}/Shared-lib.war" needxmlfile='false'>
         <fileset dir="${work.home}"/>
    <manifest>
      <attribute name="Built-By" value="Shared"/>
      <attribute name="Specification-Title" value="Shared-lib"/>
      <attribute name="Specification-Version" value="1.0"/>
      <attribute name="Implementation-Title" value="SharedLib Implementation"/>
      <attribute name="Implementation-Version" value="1.0"/>
      <attribute name="Implementation-Vendor" value="Oracle"/>
      <attribute name="Extension-Name" value="Shared-lib"/>
    </manifest>
    </war>

Step 3: Deployed the Shared-lib.war file in Application Server
image
Step 4: Now in Portal-Application.war's deployment descriptor file refer those libraries.
Deployment Descriptor file:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
    <wls:weblogic-version>12.1.1</wls:weblogic-version>
    <wls:context-root>IndustryVertical</wls:context-root>     <wls:library-ref>
        <wls:library-name>Shared-lib</wls:library-name>
        <wls:specification-version>1.0</wls:specification-version>
        <wls:exact-match>true</wls:exact-match>
     </wls:library-ref>
</wls:weblogic-web-app>

So now at runtime all your 5 different applications would be refer this bundled Shared-lib.war.
image
That’s it !! If you want have any doubts just leave reply!!

3 comments:

  1. Wouldn't these common shared libraries introduce a high level of risk and single point of failure?
    - Say you need to update one of these libraries due to accommodate one of your apps.
    As soon as you roll out the new version I can see a clear risk of breaking all four
    - If on the other hand you release this new version under a different major implementation then you would be stuck with two or more versions of the same library (until you ported all other apps to the new version)
    - The test logistic could also become nightmarish if you have many apps relying on common shared libraries.

    Disk space is now days considered cheap so I can see several bonuses of bundle each app with its own unique dependencies and a lot simpler long term management of application upgrades.

    ReplyDelete
  2. What code should I write in Pom.xml in APP1 to refer the shared library.

    ReplyDelete
  3. What code should I write in Pom.xml in APP1 to refer the shared library.

    ReplyDelete