`
lovnet
  • 浏览: 6882800 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
文章分类
社区版块
存档分类
最新评论

Writing a WebLogic Startup Class

阅读更多

Writing a WebLogic Startup Class

Introduction

This paper presents a tutorial on writing a startup class for WebLogic 6.x. It is targeted at developers who would like to use this WebLogic proprietary feature. It covers code creation and deployment into the WebLogic runtime system.

The topic of application specific data is frequently discussed in the J2EE and WebLogic newsgroups. All applications have a requirement to place frequently accessed, read-mostly global data somewhere that it can be easily used. The usual answer to these kinds of questions is to place the global data into JNDI. Why? because the powers that be, the ones who write the specs, have decided that this is the accepted way of doing it.

So? If the accepted way of of making global application data available is to place it into the naming service (JNDI) then how can this be done? Easy, implement a startup class and have WebLogic invoke it as part of its runtime initialization. This can be summarized as:

  1. Create and compile the startup class
  2. Place the startup class on the servers classpath
  3. Register the startup class via the console
  4. Start the server

Creating the Startup Class

It all begins with the creation of the startup class. BEA have made this quite straight forward, simply create a class that implements the interface weblogic.common.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. It used to be Tengah by WebLogic, now its WebLogic by BEA.

Create the class and implement the two callback methods. The first of these is the setServices method. The T3ServicesDef parameter is an object that gives you access to WebLogic proprietary internals, things such as the connection pools, workspaces, time and logging services. Much of this has now become obsolete under J2EE. For example, you use DataSources instead of directly accessing the connection pools. For this example the method can be left as a no-op. If you wanted to access the T3Services as part of your startup logic then you could store the services object in an instance variable.

The bulk of the startup logic is placed into the startup method. The startup method takes two parameters, the registered name and a hashtable. The name is set during deployment and can be used to differentiate between two registered instances of the same startup class. The hashtable contains the arguments, key/value pairs which are specified during configuration. These can be any String values. The String returned by the startup method is placed into the log. The class skeleton looks like this:

public class StartupSample implements T3StartupDef {
  public void setServices(T3ServicesDef services) {}
  public String startup(String name, Hashtable args) throws Exception {
    // do startup actions here
    return "message to appear in log";
  }
}

The coding of the startup method is quite simple, in this example a context is created within the JNDI tree and any arguments are bound into the new context. It was done this way to prevent name clashes, having a separate context prevents this from happening. Binding the arguments into the JNDI tree demonstrates what is possible and makes it easy to change. You can use the console to modify the actual data being registered into the tree. The full startup method is shown below. The complete startup class source code can be found here.

  public String startup(String name, Hashtable args) throws Exception {
    System.out.println("Startup class invoked - " + name);
    InitialContext ic = new InitialContext();
    Context startupContext = ic.createSubcontext("startup");
    // bind each argument using its name
    Enumeration keys = args.keys();
    while(keys.hasMoreElements()) {
      String key = (String)keys.nextElement();
      String value = (String)args.get(key);
      startupContext.bind(key, value);
    }
    return "ok";
  }

Deploying the Startup Class

Setting the Classpath

There is a small trick to getting the startup class to run. It must be placed on the servers classpath. That means that you need to modify the WebLogic startup script. You will need to create a directory to store your classes and place this into the CLASSPATH environment variable. For example you could create the directory path x:\bea\wlserver6.1\custom_classes and modify the startWeblogic.bat file to include it on the classpath. You must be careful which classes you place into this directory, classes loaded from the servers CLASSPATH cannot be hot deployed. If a class changes then the server must be restarted. A startup class cannot be part of a JAR, EAR or WAR file; startup classes are invoked before component classloaders are created.

Registering the Startup Class

Registering the startup class involves starting the WebLogic Server and opening the administration console in a browser. In the Deployments folder you will find the Startup & Shutdown option. From here you can elect to Configure a new Startup class. The configuration values are fairly self explanatory, the name is the String that is passed as the first parameter to the startup method. It can be set to whatever you like. The classname is the fully qualified name of the startup class. The deployment order is a number used to determine startup order when there is more than one startup class. Lowest number goes first.

Arguments allows you specify a comma separated list of key/value pairs. For example, 'abc=1,def=2' is a valid argument string. It identifies the argument 'abc' as having the value '1' and a second key of 'def' having the value '2'. Note that both the key and value are Java Strings. These arguments are passed to the startup method as the hashtable. If for some reason you need to specify a String that contains embedded blanks you must use the double quote character around the space delimited text. The abort startup on failure option will abort the server startup if an exception is thrown by the startup method. Best not to turn this on until you have the class working, if you can't start the server you can't run the console which makes it difficult to modify a poorly configured server.

When you've created the registration don't forget to target it to the server(s) that you want the startup class to run on. When you've finished you will need to restart the WebLogic server.

Summary

Now you know how easy it is to implement a WebLogic startup class. All it takes is 4 easy steps:

  1. Create and compile the startup class
  2. Place the startup class on the servers classpath
  3. Start the server
  4. Register the startup class via the console
  5. Restart the server

Enjoy!

Appendix - Code Sample

package sjdavies.wls61.startup;

import javax.naming.*;
import weblogic.common.*;
import java.util.Hashtable;
import java.util.Enumeration;

/**
 * An example of a WebLogic startup class.
 * Binds some sample values into the Naming Service.
 *
 * The top level context "startup" is created and then the startup 
 * classes arguments are bound as key/value pairs into this context.
 *
 * Copyright (c) 2001, Davies Consulting Pty. Ltd.
 *
 * @author Stephen Davies
 */

public class StartupSample implements T3StartupDef {
  public void setServices(T3ServicesDef services) {}

  /**
   * Bind selected values into the Naming Service.
   */
  public String startup(String name, Hashtable args) throws Exception {
    System.out.println("Startup class invoked - " + name);
    InitialContext ic = new InitialContext();
    Context startupContext = ic.createSubcontext("startup");
    // bind each argument using its name
    Enumeration keys = args.keys();
    while(keys.hasMoreElements()) {
      String key = (String)keys.nextElement();
      String value = (String)args.get(key);
      startupContext.bind(key, value);
    }
    return "ok";
  }
}
分享到:
评论

相关推荐

    weblogic 生成class

    weblogic weblogic生成的class

    SSH项目部署在window和linux下的Weblogic上出现 ClassNotFound异常解决办法

    ### SSH项目部署在Window和Linux下的Weblogic上出现ClassNotFound异常解决办法 #### 背景介绍 在部署Java EE项目时,特别是采用SSH(Struts + Hibernate + Spring)架构的项目,在不同的应用服务器(如Tomcat、...

    weblogic 破解和说明

    %MEDREC_WEBLOGIC_CLASSP 为 set CLASSPATH=d:\bea\weblogic_crack.jar;%CLASSPATH%;%MEDREC_WEBLOGIC_CLASSP 3. 重启weblogic linux下使用方法: 1.将license.bea和weblog_crack.jar拷贝到bea安装目录下,例如:...

    weblogic&java精华

    1. WebLogic 里面的一个 class 修改了,需要重新启动 WebLogic 吗? 答案是不需要重新启动 WebLogic。WebLogic 提供了热部署机制,可以在不重新启动的情况下部署新的类文件。 2. Tomcat 关于 UTF-8 JSP 文件的 BUG ...

    weblogic10.3.3之后版本升级至weblogic10.3.6文档.docx

    - [WebLogic Server 12.2.1.3.0与以前版本的兼容性](https://docs.oracle.com/middleware/12213/wls/WLUPG/compat.htm#GUID-B63B1939-281E-4EDF-A40D-BCA824465F42) - [10.3.3升级到10.3.6升级指南]...

    weblogic监控 weblogic调优 weblogic版本区别 weblogic启动关闭脚本

    WebLogic Server是一款由Oracle公司开发的企业级Java应用服务器,它为构建、部署和管理企业级Java应用程序提供了全面的平台。本文将深入探讨WebLogic的监控、调优、不同版本之间的区别以及启动和关闭脚本的使用。 ...

    Weblogic 套件和Weblogic 标准版 Weblogic 企业版 功能对比

    在IT领域,特别是针对企业级应用服务器的选择与配置,Oracle WebLogic Server无疑占据了重要的位置。WebLogic Server作为一款高性能、可扩展的企业级Java应用服务器,提供了丰富的功能与服务,适用于构建、部署和...

    weblogic API FOR [weblogic.jar]

    public class WebLogicAPIExample { public static void main(String[] args) throws Exception { AdminServerMBean adminServer = ManagementFactory.getAdminServer(); String version = adminServer....

    weblogic部署项目jar冲突解决

    2. **使用WebLogic的Class-Path元素**:在`weblogic.xml`配置文件中,可以使用`<class-loader>`标签来指定应用的类加载策略。例如,可以使用`delegate="false"`来让WebLogic优先使用应用自身的类库,避免与服务器...

    weblogic傻瓜式安装教程

    This can be an existing Oracle Home or a new Oracle Home ORACLE_HOME=/app/weblogic/Middleware # Set this variable value to the Installation Type selected. e.g. WebLogicServer, Coherence, Complete...

    weblogic weblogic weblogic

    WebLogic是Oracle公司的一款企业级Java应用服务器,它基于Java EE(Enterprise Edition)平台,用于构建、部署和管理分布式应用程序。WebLogic Server是许多大型企业和组织的核心组件,它提供了多种功能和服务,包括...

    eclipse的weblogic插件

    为了在Eclipse中方便地开发、调试和管理运行在WebLogic上的应用,Eclipse提供了WebLogic插件。 WebLogic插件的安装方法如描述所述,首先需要将下载的WebLogic插件压缩包解压。这个压缩包通常包含了若干个.jar文件,...

    weblogic详细安装部署手册

    ### WebLogic详细安装部署流程 #### 一、安装前准备 **1.1 JDK环境配置** - **确保JDK已安装:** 在安装WebLogic之前,必须先安装Java Development Kit (JDK)。WebLogic服务器依赖于JDK来运行。请确保安装的是与...

    weblogic10.3性能优化参数配置

    Weblogic 10.3 性能优化参数配置 Weblogic 服务器是 Oracle 公司推出的一个基于 Java 的中间件服务器,广泛应用于企业级应用系统中。为了确保 Weblogic 服务器的高性能和稳定运行,需要对其进行合理的配置和优化。...

    AIX下的Weblogic安装

    在AIX操作系统上安装Oracle WebLogic Server是一项技术性较强的任务,需要对AIX系统和WebLogic有深入的理解。本文将详细介绍在AIX环境下如何进行WebLogic的安装、配置以及启动。 首先,AIX(Advanced Interactive ...

    利用weblogic设置代理转发功能注意事项

    <servlet-class>weblogic.servlet.proxy.HttpProxyServlet</servlet-class> <param-name>WebLogicHost <param-value>192.168.9.233 <param-name>WebLogicPort <param-value>7001 ``` 集群分发配置 ...

    WebLogic License

    WebLogic License是Oracle WebLogic Server的关键组成部分,它定义了用户可以如何使用和部署这款企业级应用服务器。在Oracle收购BEA之后,WebLogic License的管理方式发生了一些变化,旨在简化授权流程并提供更大的...

    weblogic 开机自动启动

    Weblogic 开机自动启动详解 Weblogic 作为一个流行的 Java 企业级应用服务器,通常需要在服务器启动时自动启动,以确保业务的连续性。然而,在 Windows 系统下,Weblogic 的自动启动却需要进行一些额外的配置。在这...

Global site tag (gtag.js) - Google Analytics