geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Krishnakumar B <www....@gmail.com>
Subject Re: Classloading problem
Date Tue, 13 Sep 2005 03:20:55 GMT
hi

GBean plan

<?xml version="1.0" encoding="UTF-8"?>

<configuration
    xmlns="http://geronimo.apache.org/xml/ns/deployment"
    configId="test/HelloGBean"
    parentId="org/apache/geronimo/Server"
    >
     <dependency>
            <uri>test/jars/hellogbean.jar</uri>
        </dependency>

    <gbean name="HelloGBean" class="com.ibm.dw.reallybigpet.HelloGBean">
    </gbean>
</configuration>

The GBean Class

package com.ibm.dw.reallybigpet;
/**
 * Class ClientGbean
 */
public class HelloGBean implements GBeanLifecycle  {
	private static Log log = LogFactory.getLog(HelloGBean.class);
	private final ObjectName objectName;
	private static final GBeanInfo GBEAN_INFO;
	static {
	GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("HelloGBean",
				HelloGBean.class);
		// attributes
		infoFactory.addAttribute("objectName",String.class,false);
		infoFactory.setConstructor(new String[]{"objectName"});
		GBEAN_INFO = infoFactory.getBeanInfo();
	}

	public HelloGBean(String objectName) {

		this.objectName = JMXUtil.getObjectName(objectName);
	}

	public void doFail() {
		log.info("Client GBean has failed");
	}

	public void doStart() throws WaitingException, Exception {
		Hello hello = new Hello();
		log.info("Created Hello");
		log.info("Reference to Hello"+hello.getHello());
	}

	public void doStop() throws WaitingException, Exception {
		log.info("Client GBean has stoped");
	}
	public static GBeanInfo getGBeanInfo() {
		return GBEAN_INFO;
	}
}

In doStart i create an instance of Hello hello = new Hello();

package com.ibm.dw.reallybigpet;

public class Hello
{

	public static Hello hello;
	public Hello()
	{
		System.out.println("Creating the static reference :"+this);
		hello = this;
	}

	public static Hello getHello()
	{
		System.out.println("Returning the static reference :"+hello);
		return hello;
	}
}

Hello has a static variable public static Hello hello;

In a web application i am trying to get a reference to Hello by calling

Hello.getHello();

I get a null in my Web Application.

I have deployed GBean and Web Application successfully.

Thanks for any help.

Regards
Krishnakumar B




On 9/12/05, Krishnakumar B <www.bkk@gmail.com> wrote:
> Hi,
> 
> I am initializing a class and have created a static reference through
> a GBean. The GBean loads on starting the server and the Class is
> initialized and reference stored.
> 
> I have a Web app deployed in Jetty. When i try getting this Class
> reference i get a null.
> 
> I am stuck and unable to proceed. Any ideas how to proceed or fix?
> 
> The Web App plan has in dependency the GBean jar and also jar
> containing the Class initialized.
> 
> Regards
> Krishnakumar
>

Mime
View raw message