tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mohammed Javed P <mpadi...@cisco.com>
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\\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 <mpadinha@cisco.com> 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: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>    
>>
>
>
>  
>


 



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message