Author: markt Date: Tue Nov 5 00:00:56 2013 New Revision: 1538823 URL: http://svn.apache.org/r1538823 Log: Fix getURLs() so it takes account of any call to addURL() on the class loader Ensure the list of repositories that the loader returns via JMX includes any added via addURL()
Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java?rev=1538823&r1=1538822&r2=1538823&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Tue Nov 5 00:00:56 2013 @@ -1439,45 +1439,18 @@ public class WebappClassLoader extends U /** - * Returns the search path of URLs for loading classes and resources. - * This includes the original list of URLs specified to the constructor, - * along with any URLs subsequently appended by the addURL() method. - * @return the search path of URLs for loading classes and resources. + * {@inheritDoc} + * <p> + * Note that list of URLs returned by this method may not be complete. The + * web application class loader accesses class loader resources via the + * {@link WebResourceRoot} which supports the arbitrary mapping of + * additional files, directories and contents of JAR files under + * WEB-INF/classes. Any such resources will not be included in the URLs + * returned here. */ @Override public URL[] getURLs() { - - if (repositoryURLs != null) { - return repositoryURLs.clone(); - } - - WebResource webInfClasses = resources.getResource("/WEB-INF/classes"); - int resultLength; - if (webInfClasses.exists()) { - resultLength = jarRealFiles.length + 1; - } else { - resultLength = jarRealFiles.length; - } - - int off = 0; - - try { - URL[] urls = new URL[resultLength]; - if (webInfClasses.exists()) { - urls[off ++] = webInfClasses.getURL(); - } - for (File jarRealFile : jarRealFiles) { - urls[off++] = getURI(jarRealFile); - } - - repositoryURLs = urls; - - } catch (MalformedURLException e) { - repositoryURLs = new URL[0]; - } - - return repositoryURLs.clone(); - + return super.getURLs(); } @@ -1550,6 +1523,17 @@ public class WebappClassLoader extends U @Override public void start() throws LifecycleException { + WebResource classes = resources.getResource("/WEB-INF/classes"); + if (classes.exists()) { + addURL(classes.getURL()); + } + WebResource[] jars = resources.listResources("/WEB-INF/lib"); + for (WebResource jar : jars) { + if (jar.getName().endsWith(".jar")) { + addURL(jar.getURL()); + } + } + started = true; String encoding = null; try { Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java?rev=1538823&r1=1538822&r2=1538823&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java Tue Nov 5 00:00:56 2013 @@ -31,7 +31,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.net.URLDecoder; -import java.util.ArrayList; import java.util.jar.JarFile; import javax.management.ObjectName; @@ -160,12 +159,6 @@ public class WebappLoader extends Lifecy private String classpath = null; - /** - * Repositories that are set in the loader, for JMX. - */ - private ArrayList<String> loaderRepositories = null; - - // ------------------------------------------------------------- Properties /** @@ -335,10 +328,12 @@ public class WebappLoader extends Lifecy public String[] getLoaderRepositories() { - if( loaderRepositories==null ) return null; - String res[]=new String[ loaderRepositories.size()]; - loaderRepositories.toArray(res); - return res; + URL[] urls = classLoader.getURLs(); + String[] result = new String[urls.length]; + for (int i = 0; i < urls.length; i++) { + result[i] = urls[i].toExternalForm(); + } + return result; } public String getLoaderRepositoriesString() { @@ -657,7 +652,6 @@ public class WebappLoader extends Lifecy if (servletContext == null) return; - loaderRepositories = new ArrayList<>(); // Loading the work directory File workDir = (File) servletContext.getAttribute(ServletContext.TEMPDIR); @@ -680,8 +674,6 @@ public class WebappLoader extends Lifecy if(log.isDebugEnabled()) log.debug(sm.getString("webappLoader.classDeploy", classesPath, classes.getURL().toExternalForm())); - - loaderRepositories.add(classesPath + "/" ); } // Setting up the JAR repository (/WEB-INF/lib), if it exists @@ -753,8 +745,6 @@ public class WebappLoader extends Lifecy // Should ignore and continue loading other jar files // in the dir } - - loaderRepositories.add( filename ); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org