On 21/04/2015 05:59, Thusitha Thilina Dayaratne wrote: > Hi, > >> Try addURL(). >> Sorry for the inconvenience. >> As I understand addURL() method is defined in WebAppClassLoaderBase. So >> should I obtain the WebAppClassLoaderBase using getClassLoader() method > and >> use reflections to call the addURL() method? > >>> No need for reflection. Cast to URLClassloader. > >>> Note the cast *should* always work but if someone is using a strange >>> custom class loader it will fail. Note that Tomcat 7 required the class >>> loader to be an instance of WebappClassLoader. >> Thanks for quick explanation Mark. >> But still addURL() method is defined as protected. So it is not possible > to call that method by casting right? > This is my implementation with Tomcat 7 > > public class CarbonWebappLoader extends WebappLoader { > > @Override > protected void startInternal() throws LifecycleException { > WebappClassloadingContext webappClassloadingContext; > try { > webappClassloadingContext = > ClassloadingContextBuilder.buildClassloadingContext(getWebappFilePath()); > } catch (Exception e) { > throw new LifecycleException(e.getMessage(), e); > } > > for (String repository : > webappClassloadingContext.getProvidedRepositories()) { > addRepository(repository); > } > super.startInternal(); > > //Adding the WebappClassloadingContext to the WebappClassloader > ((CarbonWebappClassLoader) > getClassLoader()).setWebappCC(webappClassloadingContext); > } > > In Tomcat 8 don't have addRepository() in the WebAppLoader. Suggestion was > to use addURL() method. > But that can be access through WebAppClassLoader. So I must get the > classloader using getClassLoader() and use reflections to call addURL > method. > That would be really costly operation since it will get call for each and > every application. > > Is there a better approach than that? Or Should I move this logic to > somewhere else?
It is worth considering other options. E.g. a) Use the WebResources to map the JARs into WEB-INF/lib b) Cache the method object so reflection calls are faster. c) Ignore the performance issue since it only occurs on application start Mark --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org