I use the URLClassloader with out problem, unless Tomcat was started with the -security option, then I get
security failures. I have been using 4.1.30 and earlier. Could it be a relative directory thing, have you tried to
open the jar in your constructor to make sure you have access to the file ??


HTH
John  G

Chris Picton wrote:

Hi

I am trying to use the following code to load a class from a jar file
which is outside of my webapp directory.  The classes are loaded on
demand and dynamically.

...
public class JarClassLoader extends URLClassLoader {

  public JarClassLoader(File jar) throws MalformedURLException {
     super(new URL[] { jar.toURL() });
  }
        
  public Object instantiate(String className) throws
ClassNotFoundException, InstantiationException, IllegalAccessException {
     System.out.println("Looking for class: " + className);
     Class c = findClass(className);
     return c.newInstance();
  }
}
...
JarClassLoader loader = new JarClassLoader(new File(jarPath));
Object o = loader.instantiate(myClassName);
...


If I run the code from an app, it loads without any problems. If I use it within a tomcat Servlet, the 'instantiate' call throws a java.lang.NoClassDefFoundError.

I have checked that the tomcat user can access the jar file, so it does
not seem to be a permission problem.

Does the tomcat container limit access to classes outside of its
classpath?  Is there something simple I am missing?

Regards
Chris


---------------------------------------------------------------------
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