/** * Gets the URL that has the given class loaded from the given ClassLoader. */ private static URL getURLByClass(ClassLoader classLoader, String className) { URL resource = classLoader.getResource(className.replace('.', '/') + ".class"); if (resource == null) { throw new IllegalStateException("Failed to find .class file resource for class " + className); } return ClassLoaders.getClassPathURL(className, resource); }
/** * Gets the URL that has the given class loaded from the given ClassLoader. */ private static URL getURLByClass(ClassLoader classLoader, String className) { URL resource = classLoader.getResource(className.replace('.', '/') + ".class"); if (resource == null) { throw new IllegalStateException("Failed to find .class file resource for class " + className); } return ClassLoaders.getClassPathURL(className, resource); }
/** * Gets the URL that has the given class loaded from the given ClassLoader. */ private static URL getURLByClass(ClassLoader classLoader, String className) { URL resource = classLoader.getResource(className.replace('.', '/') + ".class"); if (resource == null) { throw new IllegalStateException("Failed to find .class file resource for class " + className); } return ClassLoaders.getClassPathURL(className, resource); }
@Override public URL getResource(String name) { URL resource = super.getResource(name); if (resource == null) { return null; } // resource = jar:file:/path/to/cdap/lib/org.scala-lang.scala-library-2.10.4.jar!/library.properties // baseClasspath = /path/to/cdap/lib/org.scala-lang.scala-library-2.10.4.jar String baseClasspath = ClassLoaders.getClassPathURL(name, resource).getPath(); String jarName = baseClasspath.substring(baseClasspath.lastIndexOf('/') + 1, baseClasspath.length()); return jarName.startsWith("org.scala-lang") ? null : resource; } }
@Override public URL getResource(String name) { URL resource = super.getResource(name); if (resource == null) { return null; } // resource = jar:file:/path/to/cdap/lib/org.scala-lang.scala-library-2.10.4.jar!/library.properties // baseClasspath = /path/to/cdap/lib/org.scala-lang.scala-library-2.10.4.jar String baseClasspath = ClassLoaders.getClassPathURL(name, resource).getPath(); String jarName = baseClasspath.substring(baseClasspath.lastIndexOf('/') + 1, baseClasspath.length()); return jarName.startsWith("org.scala-lang") ? null : resource; } }
@Override public URL getResource(String name) { URL resource = super.getResource(name); if (resource == null) { return null; } // resource = jar:file:/path/to/cdap/lib/org.scala-lang.scala-library-2.10.4.jar!/library.properties // baseClasspath = /path/to/cdap/lib/org.scala-lang.scala-library-2.10.4.jar String baseClasspath = ClassLoaders.getClassPathURL(name, resource).getPath(); String jarName = baseClasspath.substring(baseClasspath.lastIndexOf('/') + 1, baseClasspath.length()); return jarName.startsWith("org.scala-lang") ? null : resource; } }
/** * Returns the URL to the base classpath for the given class. * * @return the URL of the base classpath or {@code null} if unable to determine the URL. */ @Nullable public static URL getClassPathURL(Class<?> cls) { URL url = cls.getClassLoader().getResource(cls.getName().replace('.', '/') + ".class"); if (url == null) { return null; } return getClassPathURL(cls.getName(), url); }
/** * Returns the URL to the base classpath for the given class. * * @return the URL of the base classpath or {@code null} if unable to determine the URL. */ @Nullable public static URL getClassPathURL(Class<?> cls) { URL url = cls.getClassLoader().getResource(cls.getName().replace('.', '/') + ".class"); if (url == null) { return null; } return getClassPathURL(cls.getName(), url); }
while (resources.hasMoreElements()) { URL classURL = resources.nextElement(); File libDir = new File(ClassLoaders.getClassPathURL(className, classURL).toURI()).getParentFile();
while (resources.hasMoreElements()) { URL classURL = resources.nextElement(); File libDir = new File(ClassLoaders.getClassPathURL(className, classURL).toURI()).getParentFile();
while (resources.hasMoreElements()) { URL classURL = resources.nextElement(); File libDir = new File(ClassLoaders.getClassPathURL(className, classURL).toURI()).getParentFile();
URL sparkURL = ClassLoaders.getClassPathURL("org.apache.spark.SparkContext", sparkContextURL); LOCAL_SPARK_LIBRARIES.put(sparkCompat, Collections.singleton(new File(sparkURL.getPath()))); } else {
URL sparkURL = ClassLoaders.getClassPathURL("org.apache.spark.SparkContext", sparkContextURL); LOCAL_SPARK_LIBRARIES.put(sparkCompat, Collections.singleton(new File(sparkURL.getPath()))); } else {
URL sparkURL = ClassLoaders.getClassPathURL("org.apache.spark.SparkContext", sparkContextURL); LOCAL_SPARK_LIBRARIES.put(sparkCompat, Collections.singleton(new File(sparkURL.getPath()))); } else {
if (!urls.remove(ClassLoaders.getClassPathURL(mainClassName, resource))) { throw new IllegalStateException("Failed to remove main class resource " + resource);
if (!urls.remove(ClassLoaders.getClassPathURL(mainClassName, resource))) { throw new IllegalStateException("Failed to remove main class resource " + resource);
URL jaxrsURL = ClassLoaders.getClassPathURL(Path.class); String jaxrsClassPath = null;
URL jaxrsURL = ClassLoaders.getClassPathURL(Path.class); String jaxrsClassPath = null;