You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Daniel Kehoe <ke...@fortuity.com> on 2000/02/15 01:47:17 UTC
why ClassNotFoundException on attempt to dynamically load a class?
Why does this code throw an exception
"java.lang.ClassNotFoundException: SpecificReport"?
String dynamicReportName = "SpecificReport";
myReport = (myReportInterface)Class.forName(dynamicReportName).newInstance();
It works fine if I just instantiate the object:
SpecificReport aSpecificReport = new SpecificReport();
And it works fine under Jserv or Jrun.
I hear someone asking, why does he want to do this? Answer: I want to
load a class dynamically based on a parameter passed from the
browser, like:
String dynamicReportName = request.getParameterValues("report")[0];
I'm using Tomcat 3.1M1 with java 1.2.2 Classic VM (build
Linux_JDK_RC3, native threads, sunwjit). What's going on that's
different?
Thanks!
RE: why ClassNotFoundException on attempt to dynamically load a
class?
Posted by Daniel Kehoe <ke...@fortuity.com>.
At 5:42 PM -0800 2/14/00, Angsuman wrote:
>Hazarding a guess, has the default class loader been changed?
No. The servlet that uses the Class.forName method is in a directory
/home/docroot/testbed/WEB-INF/classes
and I have an entry in the server.xml file:
<Context path="/testbed" docBase="/home/docroot/testbed"
defaultSessionTimeOut="30" isWARExpanded="true"
isWARValidated="false" isInvokerEnabled="true"
isWorkDirPersistent="false"/>
and I request the servlet like this:
http://www.myserver.com/testbed/servlet/myServlet
I haven't made any changes to the Tomcat default configuration except
to set the port to 80 and set the tomcat.sh script to include
JAVA_HOME=/usr/local/jdk1.2.2.
I suppose it has something to do with how classes are loaded. Is
Tomcat doing something different than other servlet engines?
Daniel
kehoe@fortuity.com
RE: why ClassNotFoundException on attempt to dynamically load a class?
Posted by Angsuman <an...@technologist.com>.
Hazarding a guess, has the default class loader been changed?
-----Original Message-----
From: Daniel Kehoe [mailto:kehoe@fortuity.com]
Sent: Monday, February 14, 2000 4:47 PM
To: tomcat-dev@jakarta.apache.org
Subject: why ClassNotFoundException on attempt to dynamically load a
class?
Why does this code throw an exception
"java.lang.ClassNotFoundException: SpecificReport"?
String dynamicReportName = "SpecificReport";
myReport =
(myReportInterface)Class.forName(dynamicReportName).newInstance();
It works fine if I just instantiate the object:
SpecificReport aSpecificReport = new SpecificReport();
And it works fine under Jserv or Jrun.
I hear someone asking, why does he want to do this? Answer: I want to
load a class dynamically based on a parameter passed from the
browser, like:
String dynamicReportName = request.getParameterValues("report")[0];
I'm using Tomcat 3.1M1 with java 1.2.2 Classic VM (build
Linux_JDK_RC3, native threads, sunwjit). What's going on that's
different?
Thanks!
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org