tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1810330 - /tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappLoader.java
Date Mon, 02 Oct 2017 10:23:19 GMT
Author: markt
Date: Mon Oct  2 10:23:19 2017
New Revision: 1810330

URL: http://svn.apache.org/viewvc?rev=1810330&view=rev
Log:
Java 9 The JRE class loaders no longer extend URLClassLoader

Modified:
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappLoader.java

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappLoader.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappLoader.java?rev=1810330&r1=1810329&r2=1810330&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappLoader.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/loader/WebappLoader.java Mon Oct  2 10:23:19
2017
@@ -30,7 +30,6 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -1075,8 +1074,7 @@ public class WebappLoader extends Lifecy
     private boolean buildClassPath(ServletContext servletContext,
             StringBuilder classpath, ClassLoader loader) {
         if (loader instanceof URLClassLoader) {
-            URL repositories[] =
-                    ((URLClassLoader) loader).getURLs();
+            URL repositories[] = ((URLClassLoader) loader).getURLs();
                 for (int i = 0; i < repositories.length; i++) {
                     String repository = repositories[i].toString();
                     if (repository.startsWith("file://"))
@@ -1094,16 +1092,20 @@ public class WebappLoader extends Lifecy
                         classpath.append(File.pathSeparator);
                     classpath.append(repository);
                 }
-        } else {
-            String cp = getClasspath(loader);
-            if (cp == null) {
-                log.info( "Unknown loader " + loader + " " + loader.getClass());
-            } else {
-                if (classpath.length() > 0)
+        } else if (loader == ClassLoader.getSystemClassLoader()){
+            // Java 9 onwards. The internal class loaders no longer extend
+            // URLCLassLoader
+            String cp = System.getProperty("java.class.path");
+            if (cp != null && cp.length() > 0) {
+                if (classpath.length() > 0) {
                     classpath.append(File.pathSeparator);
+                }
                 classpath.append(cp);
             }
             return false;
+        } else {
+            log.info( "Unknown loader " + loader + " " + loader.getClass());
+            return false;
         }
         return true;
     }
@@ -1118,26 +1120,6 @@ public class WebappLoader extends Lifecy
         return result;
     }
 
-    // try to extract the classpath from a loader that is not URLClassLoader
-    private String getClasspath( ClassLoader loader ) {
-        try {
-            Method m=loader.getClass().getMethod("getClasspath", new Class[] {});
-            if( log.isTraceEnabled())
-                log.trace("getClasspath " + m );
-            Object o=m.invoke( loader, new Object[] {} );
-            if( log.isDebugEnabled() )
-                log.debug("gotClasspath " + o);
-            if( o instanceof String )
-                return (String)o;
-            return null;
-        } catch( Exception ex ) {
-            Throwable t = ExceptionUtils.unwrapInvocationTargetException(ex);
-            ExceptionUtils.handleThrowable(t);
-            if (log.isDebugEnabled())
-                log.debug("getClasspath ", ex);
-        }
-        return null;
-    }
 
     /**
      * Copy directory.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message