Thanks Craig for correcting my forName() mistake. But do you have any suggestions for the casting issue?
Regards, Thierry -----Original Message----- From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]] Sent: Saturday, July 13, 2002 7:57 PM To: Tomcat Users List; [EMAIL PROTECTED] Subject: RE: ClassCast exception On Sat, 13 Jul 2002, Thierry Thelliez wrote: > Date: Sat, 13 Jul 2002 19:46:36 -0600 > From: Thierry Thelliez <[EMAIL PROTECTED]> > Reply-To: Tomcat Users List <[EMAIL PROTECTED]>, [EMAIL PROTECTED] > To: 'Tomcat Users List' <[EMAIL PROTECTED]> > Subject: RE: ClassCast exception > > > More details to the problem described in the first email. > > I have now tried another scenario: > > My parent class (B) is now sitting in a jar in WEB-INF/lib. > My subClass (A) is in a .class in WEB-INF/classes. > B and A are in different packages (p1.x.B and p2.A). > > The code with the casting issue is in a static method of A. > > B b = doSomething(); -> Works > > log("B " + b.getClass().getName()); -> p1.x.B > log("B " + b.getClass().getClassLoader()); -> CL1 > > log("A " + A.class.getClassLoader()); -> CL2 (seems to be = > to CL1) > That will generally be true -- the container sets up a single class loader for everything in WEB-INF/classes and WEB-INF/lib. > ( b.getClass().getClassLoader()) == > Class.forName("p2.A").getClassLoader())); -> true > > ( b.getClass().getClassLoader()) == > Class.forName("A").getClassLoader())); -> Class not found... This is never going to work. The argument to Class.forName has to be the fully qualified class name. See the Javadocs on java.lang.Class for more. > > A a = (A) doSomething(); -> > ClassCastException... > > > > I have been through extensive web search. It seems that this problem is > not uncommon but I cannot figure out how to solve it... > > (How do you get the instance id for the ClassLoaders? In the output in > my first email, my class loaders are giving me a name, not a unique id) > > Help! > > Thierry > Craig > -----Original Message----- > From: Thierry Thelliez [mailto:[EMAIL PROTECTED]] > Sent: Saturday, July 13, 2002 6:04 PM > To: [EMAIL PROTECTED] > Subject: ClassCast exception > > Hello, > > I have a ClassCast problem. I read the archive and attempted few > suggestions (like grouping everything in one jar in WEB-INF/lib) without > success. > > I am using tomcat 4.0.4 and 1.3.1_02 under Solaris. > > Someone suggested looking at the ClassLoaders. The following is > generated by something like: > Log4j("MyClass " + MyClass.class.getClassLoader()); > > -------------------------------------------------------------------- > 2002-07-13 18:36:56,808 - - MyClass WebappClassLoader > available: > delegate: false > repositories: > required: > ----------> Parent Classloader: > StandardClassLoader > available: > delegate: true > repositories: > file:/serverPath/jakarta-tomcat-4.0.4/classes/ > file:/serverPath/jakarta-tomcat-4.0.4/lib/jasper-runtime.jar > file:/serverPath/jakarta-tomcat-4.0.4/lib/jasper-compiler.jar > file:/serverPath/jakarta-tomcat-4.0.4/lib/naming-factory.jar > required: > ----------> Parent Classloader: > StandardClassLoader > available: > Extension[javax.mail, implementationVendor=Sun Microsystems, Inc., > implementationVendorId=com > .sun, implementationVersion=1.2, specificationVendor=Sun Microsystems, > Inc., specificationVersion > =1.2] > delegate: true > repositories: > file:/serverPath/jakarta-tomcat-4.0.4/common/classes/ > file:/serverPath/jakarta-tomcat-4.0.4/common/lib/naming-common.jar > file:/serverPath/jakarta-tomcat-4.0.4/common/lib/servlet.jar > > file:/serverPath/jakarta-tomcat-4.0.4/common/lib/naming-resources.jar > file:/serverPath/jakarta-tomcat-4.0.4/common/lib/jdbc2_0-stdext.jar > file:/serverPath/jakarta-tomcat-4.0.4/common/lib/activation.jar > file:/serverPath/jakarta-tomcat-4.0.4/common/lib/jta-spec1_0_1.jar > file:/serverPath/jakarta-tomcat-4.0.4/common/lib/xerces.jar > file:/serverPath/jakarta-tomcat-4.0.4/common/lib/tyrex-0.9.7.0.jar > file:/serverPath/jakarta-tomcat-4.0.4/common/lib/mail.jar > file:/serverPath/jakarta-tomcat-4.0.4/common/lib/jndi.jar > file:/serverPath/jakarta-tomcat-4.0.4/common/lib/cos.jar > required: > ----------> Parent Classloader: > sun.misc.Launcher$AppClassLoader@3f52a5 > > > --------------------------------- > > just after that I try a Class.forName("MyClass"); > but I get a ClassNotFound exception. > > > Is that normal that I don't see listed the webapps/myApp/WEB-INF/lib in > the repositories above? > > In the ClassCast issue, both classes return the same loader. > > Thanks, > Thierry > > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> > > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
