Hi,

I noticed an incompatibility after testing my web application with Tomcat 8 RC5 and Tomcat 8.0.1

I allow users of my web application to configure the web application with external configuration. This is also where the user is allowed to specify additional libraries to load into the web application (e.g. database driver).

This code worked in Tomcat 7 and Jetty 8 - 9.1 but does not work anymore in the current version of Tomcat:

if (libDir != null && libDir.isDirectory()) {
  File[] listFiles = libDir.listFiles(new FilenameFilter() {
    public boolean accept(File dir, String name) {
      return name.toLowerCase().endsWith(".jar");
    }
  });
  if (listFiles.length > 0) {
    ClassLoader classLoader = this.getClass().getClassLoader();
    Class<? extends ClassLoader> classLoaderClass =
      classLoader.getClass();
    try {
      Method addUrlMethod =
        URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
      addUrlMethod.setAccessible(true);
      for (File jarFile : listFiles) {
        try {
          addUrlMethod.invoke(classLoader, jarFile.toURI().toURL());
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | MalformedURLException e) {
          e.printStackTrace();
        }
      }
    } catch (NoSuchMethodException | SecurityException e) {
      e.printStackTrace();
  }
}

Using Tomcat 8 there is no error message when I use the "addURL" method. But any class inside the jar files is not found afterwards.

Any help to work-around the problem is highly appreciated :-)

kind regards,

Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to