You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Krishnakumar B <ww...@gmail.com> on 2005/09/12 12:10:41 UTC

Classloading problem

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

Re: Classloading problem

Posted by Krishnakumar B <ww...@gmail.com>.
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 <ww...@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
>

Re: Classloading problem

Posted by David Jencks <da...@yahoo.com>.
I find some of your description ambiguous.  For instance, what do you 
mean by "The GBean loads on starting the server"? Do you have a <gbean 
..../> element in your geronimo-web.xml plan that creates a gbean 
instance using your gbean class?  Simply loading a class that can be 
used as a gbean does not register an instance of that class with the 
kernel, or call the constructor or lifecycle methods.  If this does not 
help you resolve the issue we need the code in question and the 
geronimo plan with the gbean definition.

thanks
david jencks

On Sep 12, 2005, at 3:10 AM, Krishnakumar B 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
>