You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Lynn Rice <dr...@dmotorworks.com> on 2000/07/25 00:55:25 UTC

getting error message "Cannot create bean of class beanProperties"

########## Environment
Tomcat: 3.1 SunJDK: 1.2.2 Linux

I am trying to implement an interface that contains some global strings in a
very simple interface:

public interface Properties {
	public static final String FOO_INFORMATION = "Information";
}

I use this interface to give static String properties to several classes and
servlets, but I also need to be able to get to these Properties from a jsp.
And, in order to use it in a jsp, I implement a dummy class like this (it is
in WEB-INF classes):

public class beanProperties implements Properties { }

This way I can instantiate the beanProperties object and access these
strings using something like this:

<jsp:useBean id="prop" scope="page" class="beanProperties" />

and

<%= prop.FOO_INFORMATION %>



########## Problem

If I recompile ANY classes, then I get a ServletException that says "Cannot
create bean of class beanProperties"

It looks like the Jasper engine generates the following piece of code:
	try {
		prop = (beanProperties) Beans.instantiate(getClassLoader(),
"beanProperties");
	} catch (Exception exc) {
		throw new ServletException (" Cannot create bean of class
"+"beanProperties\n");
	}

and according to the API instantiate can either return a IOException or a
ClassNotFoundException, but I can't tell what type of exception is being
thrown.

Basically, I cannot figure out why this is happening, but it is preventing
me from using the Class reloading feature because I end up restarting tomcat
everytime I recompile anything.

~David


RE: getting error message "Cannot create bean of class beanProperties"

Posted by "Rob S." <rs...@home.com>.
There are a couple of ways that I've seen:

1) If you're looking for something you'll only use in JSPs, I've seen people
use a properties.jsp or sorts, where the entire file is a <%! ... %> of
declarations.  This is more for things like email addresses and whatnot I
suppose.

2) For application use, I just use a static properties class.  The only
thing I haven't bothered trying to figure out is where it will look for
properties by default (class dir, tomcat dir, etc.) so I just hardcoded the
properties location =)  In my class, static initialization takes care of
bringing in the properties, and from all of my JSPs and logic, I just do
AppProperties.getProperty().

HTH!

- r

> -----Original Message-----
> From: David Lynn Rice [mailto:drice@dmotorworks.com]
> Sent: July 24, 2000 6:35 PM
> To: tomcat-user@jakarta.apache.org
> Subject: RE: getting error message "Cannot create bean of class
> beanProperties"
>
>
> 	My actual example is in a package and I do specify the full
> package in the
> useBean declaration, but it still has the problem of getting the "Cannot
> create bean of class beanProperties" error message.
>
> 	If there is a better way to implement something like
> Properties in java, I
> would be more than willing to explore an alternative implementation.
>
> ~David
>
>
> -----Original Message-----
> From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
> Sent: Monday, July 24, 2000 8:21 PM
> To: tomcat-user@jakarta.apache.org
> Subject: Re: getting error message "Cannot create bean of class
> beanProperties"
>
>
> David Lynn Rice wrote:
>
> > ########## Environment
> > Tomcat: 3.1 SunJDK: 1.2.2 Linux
> >
> > I am trying to implement an interface that contains some global
> strings in
> a
> > very simple interface:
> >
> > public interface Properties {
> >         public static final String FOO_INFORMATION = "Information";
> > }
> >
> > I use this interface to give static String properties to several classes
> and
> > servlets, but I also need to be able to get to these Properties from a
> jsp.
> > And, in order to use it in a jsp, I implement a dummy class
> like this (it
> is
> > in WEB-INF classes):
> >
> > public class beanProperties implements Properties { }
> >
> > This way I can instantiate the beanProperties object and access these
> > strings using something like this:
> >
> > <jsp:useBean id="prop" scope="page" class="beanProperties" />
> >
> > and
> >
> > <%= prop.FOO_INFORMATION %>
> >
> > ########## Problem
> >
> > If I recompile ANY classes, then I get a ServletException that says
> "Cannot
> > create bean of class beanProperties"
> >
> > It looks like the Jasper engine generates the following piece of code:
> >         try {
> >                 prop = (beanProperties)
> Beans.instantiate(getClassLoader(),
> > "beanProperties");
> >         } catch (Exception exc) {
> >                 throw new ServletException (" Cannot create
> bean of class
> > "+"beanProperties\n");
> >         }
> >
> > and according to the API instantiate can either return a
> IOException or a
> > ClassNotFoundException, but I can't tell what type of exception is being
> > thrown.
> >
> > Basically, I cannot figure out why this is happening, but it is
> preventing
> > me from using the Class reloading feature because I end up restarting
> tomcat
> > everytime I recompile anything.
> >
>
> The generated code shown above has been modified to include the "exc"
> exception
> as a second argument to the ServletException constructor (in the current
> development code base, but not yet folded into a beta for Tomcat 3.2),
> so you
> will a least be able to see what underlying exception was thrown.  It
> will be
> logged as the "root cause" of this exception in Tomcat's logs.
>
> One problem you will have is that your "beanProperties" class appears
> not to be
> in a package.  This causes problems because the "default" package
> codebase
> varies with where the JSP page itself is.  A solution would be to define
> this
> class in a package, and declare the fully qualified classname in the
> <jsp:useBean> declaration.
>
> >
> > ~David
>
> Craig McClanahan
>
>


RE: getting error message "Cannot create bean of class beanProperties"

Posted by David Lynn Rice <dr...@dmotorworks.com>.
	My actual example is in a package and I do specify the full package in the
useBean declaration, but it still has the problem of getting the "Cannot
create bean of class beanProperties" error message.

	If there is a better way to implement something like Properties in java, I
would be more than willing to explore an alternative implementation.

~David


-----Original Message-----
From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
Sent: Monday, July 24, 2000 8:21 PM
To: tomcat-user@jakarta.apache.org
Subject: Re: getting error message "Cannot create bean of class
beanProperties"


David Lynn Rice wrote:

> ########## Environment
> Tomcat: 3.1 SunJDK: 1.2.2 Linux
>
> I am trying to implement an interface that contains some global strings in
a
> very simple interface:
>
> public interface Properties {
>         public static final String FOO_INFORMATION = "Information";
> }
>
> I use this interface to give static String properties to several classes
and
> servlets, but I also need to be able to get to these Properties from a
jsp.
> And, in order to use it in a jsp, I implement a dummy class like this (it
is
> in WEB-INF classes):
>
> public class beanProperties implements Properties { }
>
> This way I can instantiate the beanProperties object and access these
> strings using something like this:
>
> <jsp:useBean id="prop" scope="page" class="beanProperties" />
>
> and
>
> <%= prop.FOO_INFORMATION %>
>
> ########## Problem
>
> If I recompile ANY classes, then I get a ServletException that says
"Cannot
> create bean of class beanProperties"
>
> It looks like the Jasper engine generates the following piece of code:
>         try {
>                 prop = (beanProperties)
Beans.instantiate(getClassLoader(),
> "beanProperties");
>         } catch (Exception exc) {
>                 throw new ServletException (" Cannot create bean of class
> "+"beanProperties\n");
>         }
>
> and according to the API instantiate can either return a IOException or a
> ClassNotFoundException, but I can't tell what type of exception is being
> thrown.
>
> Basically, I cannot figure out why this is happening, but it is preventing
> me from using the Class reloading feature because I end up restarting
tomcat
> everytime I recompile anything.
>

The generated code shown above has been modified to include the "exc"
exception
as a second argument to the ServletException constructor (in the current
development code base, but not yet folded into a beta for Tomcat 3.2),
so you
will a least be able to see what underlying exception was thrown.  It
will be
logged as the "root cause" of this exception in Tomcat's logs.

One problem you will have is that your "beanProperties" class appears
not to be
in a package.  This causes problems because the "default" package
codebase
varies with where the JSP page itself is.  A solution would be to define
this
class in a package, and declare the fully qualified classname in the
<jsp:useBean> declaration.

>
> ~David

Craig McClanahan


Re: getting error message "Cannot create bean of class beanProperties"

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
David Lynn Rice wrote:

> ########## Environment
> Tomcat: 3.1 SunJDK: 1.2.2 Linux
>
> I am trying to implement an interface that contains some global strings in a
> very simple interface:
>
> public interface Properties {
>         public static final String FOO_INFORMATION = "Information";
> }
>
> I use this interface to give static String properties to several classes and
> servlets, but I also need to be able to get to these Properties from a jsp.
> And, in order to use it in a jsp, I implement a dummy class like this (it is
> in WEB-INF classes):
>
> public class beanProperties implements Properties { }
>
> This way I can instantiate the beanProperties object and access these
> strings using something like this:
>
> <jsp:useBean id="prop" scope="page" class="beanProperties" />
>
> and
>
> <%= prop.FOO_INFORMATION %>
>
> ########## Problem
>
> If I recompile ANY classes, then I get a ServletException that says "Cannot
> create bean of class beanProperties"
>
> It looks like the Jasper engine generates the following piece of code:
>         try {
>                 prop = (beanProperties) Beans.instantiate(getClassLoader(),
> "beanProperties");
>         } catch (Exception exc) {
>                 throw new ServletException (" Cannot create bean of class
> "+"beanProperties\n");
>         }
>
> and according to the API instantiate can either return a IOException or a
> ClassNotFoundException, but I can't tell what type of exception is being
> thrown.
>
> Basically, I cannot figure out why this is happening, but it is preventing
> me from using the Class reloading feature because I end up restarting tomcat
> everytime I recompile anything.
>

The generated code shown above has been modified to include the "exc"
exception
as a second argument to the ServletException constructor (in the current
development code base, but not yet folded into a beta for Tomcat 3.2),
so you
will a least be able to see what underlying exception was thrown.  It
will be
logged as the "root cause" of this exception in Tomcat's logs.

One problem you will have is that your "beanProperties" class appears
not to be
in a package.  This causes problems because the "default" package
codebase
varies with where the JSP page itself is.  A solution would be to define
this
class in a package, and declare the fully qualified classname in the
<jsp:useBean> declaration.

>
> ~David

Craig McClanahan