tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mohammed Javed P <>
Subject Re: Loading a class from a zip file , present outside Tomcat directories
Date Fri, 31 Oct 2003 16:20:37 GMT
  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\\").toURL() };
                        String classFile= ""; // the class to be loaded from the file

                       ClassLoader tempClassLoader 
                        ClassLoader cl = new 

                      System.out.println("DEBUG: :Before calling 
                       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 <> wrote:
>>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!
>>To unsubscribe, e-mail:
>>For additional commands, e-mail:


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message