Pages

Monday, May 3, 2010

Working With Weblogic Startup & Shutdown classes

Share it Please
There is many times where an application needs to get global data to perform some sort of functionality. They may use the global data which may contain many parameters like jms , jdbc , connection pool information which will be used while serving to the client requests. These sorts of global data, frequently used data should be kept in somewhere easily accessed by application. The Best place is to place them in JNDI [Java Naming And Directory Interface].if it to be placed in the JNDI, How can it be done in Weblogic . the answer to this questions is by using a StartUp class.

A startup class in weblogic is nothing but a class which gets executed when the server is starting up. Similarly the Shutdown works the wasy the name says.

In this article we will see how we can create a startup class and deploy it to a target to get executed when the target is starting up.

Create A Start Up Class: in order to create a start up class in weblogic we need to implement the weblogic related interface T3StartupDef . If you're wondering about the 'T3', the unofficial word is that it stands for Tengah 3, which I believe was the old name for the product before the WebLogic Company was purchased by BEA.this interface provides 2 methods to implement


public void setServices(T3ServicesDef arg0) {

}

public String startup(String arg0, Hashtable arg1) throws Exception {
return null;
}


The first method takes an argumernt T3ServicesDef which is an object which gives you access to the weblogic internal like connection pools ,logging and workspaces and more .

The second method takes 2 arguments String, Hashtable where the first argument is the name that we specified during the creation of startup class. If we specify the name of the startup class in weblogic console as “startUp-0”, then the first argument holds this name. The second argument is a hashtable which takes all the arguments that we send through the start up to be kept in jndi.these can by any string values.


Here is the same code

public class sampleClass implements T3StartupDef {

public void setServices(T3ServicesDef arg0) {

}

public String startup(String arg0, Hashtable arg1) throws Exception {
System.out.println("Startup class invoked - " + arg0);
return "Invoked Class Is Here And Successfully";
}


public static void main(String[] args) {

}

}

Creating a Startup Class In Weblogic Console :
Click “startup and Shutdown class” in left hand tree
Select “startup Class” -> Next
Keep the Name and enter the class Name [ Class name for above example : com.jagadesh.sampleClass ] -> Next
Select the Target and Finnish

Now the important part, we need to make sure the class is in the server class path , for this we need to edit setDomainEnv.cmd [ windows ] to add the class to the server class path.

If we need to add a jar to all domains, we can copy the jar file to WL_HOME/server/lib . the CommEnv.cmd will include the jar when the server is starting up. We will edit the CommEnv.cmd and prepend the jar file to WEBLOGIC_CLASSPATH

If we need to add to a specific domain, we will edit the setDomainEnv.cmd file available in that domain bin directory and add the jar entry to PRE_CLASSPATH

I created the jar file by the name Sam and added it to the setDomainEnv.cmd as below

@REM Clear the pre_classpath here in case an application template wants to set it before the larger pre_classpath id below

set PRE_CLASSPATH=C:/software/Sam.jar;

just search for the PRE_CLASSPATH and on the right hand side give your jar location.

Now we can restart the server and in the log file after the server restarted we can see the contents which we defined in the startup method like


<1270705581990> <BEA-000287> <Invoking startup class: com.jagadesh.sampleClass.startup(null)>
####<Apr 8, 2010 12:46:21 AM CDT> <Info> <WebLogicServer> <PKMI-DS00C2B17> <desktop_server> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1270705581990> <BEA-000288> <com.jagadesh.sampleClass reports: Invoked Class Is Here And Successfully>


See weblogic docs for writing advanced start up and shutdown scripts

2 comments :

  1. Hmm it looks like your blog ate my first comment (it was super long) so I guess I'll just
    sum it up what I wrote and say, I'm thoroughly enjoying your blog.
    I too am an aspiring blog writer but I'm still
    new to the whole thing. Do you have any points
    for rookie blog writers? I'd really appreciate it.


    Here is my web site :: gta san andreas ios download (youtube.com)

    ReplyDelete
  2. I have been searching online more than three hours today, yet I never
    found interesting article like this one. In my view, if all web owners and blggers made good content as you did, the internet will
    be much more useful thaqn ever before.

    ReplyDelete