Use the following code. U will b able to invoke.
String szClassName = "Ext1";
Class cls =
Class.forName(szClassName);
String szMethodName = "method";
Class parType[] = new Class[1];
parType[0] =
Class.forName("java.io.File");
java.lang.reflect.Method met =
cls.getMethod(szMethodName, parType);
Object clObj = cls.newInstance();
Object arg[] = new java.io.File[1];
arg[0] = (File)<some file object>;
Object bp = met.invoke(clObj, arg);
Sabari Arasu
AIG-TCS,
Ambattur,
Chennai(Madras),
India.
Ph: 91 - 44 - 6256437 Xtn:321
> -----Original Message-----
> From: Puneet Mathur [SMTP:[EMAIL PROTECTED]]
> Sent: Friday, January 25, 2002 10:56 AM
> To: [EMAIL PROTECTED]
> Subject: Need help with forName()
>
> Hi all
>
> I need help with dynamically loading classes using the forName(..) method
> of Class.
>
> I have a servlet which gets a 'application name' as a parameter -
> 'application name' is nothing but name of a Java class.
>
> Say the 'application name' is "Ext1", we have a class called 'Ext1.class'
> containing a set of methods.
>
>
> public class Ext1 {
> public static String returnSomething(String sParam1) {
> return "return from Ext1.returnSomething() with argument=" + sParam1;
> }
> }
>
> Now, my servlet contains the following code:
> ....
> import java.lang.reflect.*;
> ....
> String sApplName = "Ext1";
> Class c = Class.forName (sApplName);
> Object o = c.newInstance();
>
> Now, I want to invoke 'returnSomething(..)' method and get the return
> string value.
>
> How do I do it?
>
> Any help will be highly appreciated. Thanks in advance.
>
> Puneet
> ([EMAIL PROTECTED])
>
>
>
>
> **********************************************************************
> ***** IMPORTANT INFORMATION *****
> This document should be read only by those persons to whom
> it is addressed and its content is not intended for use by
> any other persons. If you have received this message in
> error, please notify us immediately. Please also destroy and
> delete the message from your computer. Any unauthorised form
> of reproduction of this message is strictly prohibited.
> St.George is not liable for the proper and complete transmission
> of the information contained in this communication, nor for any
> delay in its receipt.
> **********************************************************************
>
> __________________________________________________________________________
> _
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html