Hi geeks,

Problem :-

I have a zip file which contains a ".class " file . I need to create an instance of this class during runtime.
Below is the snippet from the actual code which does the same.


I was able to successfully load the classes when running test routine using the same code through the command line.

But when i call the same API from the GUI [running in Tomcat 3.3.1] , I am unable to load the class.It was giving me java.lang.ClassFormatError: (Bad magic number)
NOTE : The zip file is not under the Tomcat directory.



I understand that the classloader mechanism for Tomcat is different.I tried the following approach
- I tried loading it from the webapp classloader's parent, ie. right upto the same system classloader as used by command line, by using getParent() .(myPkg.tryMe.class.getClassLoader().getParent() ) ..
... but am still in same square, as am getting the same exception.
Any help on this is welcome.




=======================code snippet=====================
package myPkg;
public class tryMe{
public static void loadMyClass(){
URL[] urls = { new File("C:\\tmp\\abcd.zip").toURL() };
String classFile= " com.xxx.yy.myClassToBeLoaded"; // the class to be loaded from the abcd.zip file


ClassLoader tempClassLoader =myPkg.tryMe.class.getClassLoader();
ClassLoader cl = new URLClassLoader(urls,tempClassLoader);


System.out.println("DEBUG: :Before calling loadclass..:");
Object o = cl.loadClass(classFile).newInstance();
System.out.println(" DEBUG:: successfully loaded class ..");
}


} //EOC
=======================End of code snippet===================

Thanks in advance,
~  ~Javed


--- Mohammed Javed P <[EMAIL PROTECTED]> wrote:



Hi!


Is it possible to load a class from a zip file , which is located outside the Tomcat directories ?
I mean, the zip file can be anywhere in the hard disk, and not under the installed Tomcat directory structure.


Please provide any pointers on how to go about it .

Thnkx in advance!

regards,
~Javed




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]













---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to