From 11e2ee92586d3818afee1a82128ad1e650eac37d Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Thu, 25 Jan 2018 20:12:19 -0800 Subject: [PATCH] [BEAM-2530] Make classloader handling more compatible with JDK 9 From http://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html: > The application class loader is no longer an instance of > java.net.URLClassLoader (an implementation detail that was never > specified in previous releases). Code that assumes that > ClassLoader::getSytemClassLoader returns a URLClassLoader object will > need to be updated. Note that Java SE and the JDK do not provide an > API for applications or libraries to dynamically augment the class > path at run-time. --- .../beam/runners/core/construction/PipelineResources.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/PipelineResources.java b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/PipelineResources.java index ae6b076acf25..524a0c357b33 100644 --- a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/PipelineResources.java +++ b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/PipelineResources.java @@ -17,6 +17,8 @@ */ package org.apache.beam.runners.core.construction; +import com.google.common.base.Splitter; +import com.google.common.base.StandardSystemProperty; import java.io.File; import java.net.URISyntaxException; import java.net.URL; @@ -37,6 +39,11 @@ public class PipelineResources { * @return A list of absolute paths to the resources the class loader uses. */ public static List detectClassPathResourcesToStage(ClassLoader classLoader) { + if (classLoader == ClassLoader.getSystemClassLoader()) { + return Splitter.on(File.pathSeparatorChar) + .splitToList(StandardSystemProperty.JAVA_CLASS_PATH.value()); + } + if (!(classLoader instanceof URLClassLoader)) { String message = String.format("Unable to use ClassLoader to detect classpath elements. " + "Current ClassLoader is %s, only URLClassLoaders are supported.", classLoader);