On 10/02/2014 10:58, Thomas Scheffler wrote:
> 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();
>   }
> }

When you start using reflection to access class loader internals (or any
other internals) that is usually a sign that the solution is going to be
fragile. In this case, the resources refactoring in Tomcat 8 removed a
whole bunch of code from WebappClassLoader, including the addURL
implementation.

The 'correct' way to do this in Tomcat add is to add an appropriate
nested <Resources ... /> element to the context.

It may be possible to restore the functionality you were depending on.
Are you able to build Tomcat 8 from trunk and test it if I make some
changes?

The ideal solution would be for this to be handled as part of the
Servlet spec. Hopefully, the concept of overlays (which should handle
this) will return in 3.2 after being pulled from 3.1.

Mark


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

Reply via email to