diff --git a/modules/graphics/src/main/java/com/sun/javafx/css/converters/URLConverter.java b/modules/graphics/src/main/java/com/sun/javafx/css/converters/URLConverter.java --- a/modules/graphics/src/main/java/com/sun/javafx/css/converters/URLConverter.java +++ b/modules/graphics/src/main/java/com/sun/javafx/css/converters/URLConverter.java @@ -114,20 +114,22 @@ final String stylesheetPath = (stylesheetUrl != null) ? stylesheetUrl.trim() : null; if (stylesheetPath != null && stylesheetPath.isEmpty() == false) { - URI stylesheetUri = new URI(stylesheetPath); - if (stylesheetUri.isOpaque() == false) { - + if (stylesheetUri.isOpaque()) { + // stylesheet URI is something like jar:file: + // if the path starts with '/', then it will resolve relative to the root of the jar file. + // If stylesheetUri is "jar:file://foo/bar.jar!/com/wickedcool/ui/styles.css" + // and the resourceUri is "/shared/resources/image.png", + // then new URL("jar:file://foo/bar.jar!/com/wickedcool/ui/styles.css", "/shared/resources/image.png") + // will be "jar:file://foo/bar.jar!/shared/resources/image.png" + URL url = stylesheetUri.toURL(); + return new URL(url, resourceUri.getPath()); + } else if (!resourceUri.getPath().startsWith("/")) { + // if path starts with '/', then the path is considered relative to the class-path + // and the URL is resolved with the ClassLoader getResource() call below. URI resolved = stylesheetUri.resolve(resourceUri); return resolved.toURL(); - - } else { - - // stylesheet URI is something like jar:file: - URL url = stylesheetUri.toURL(); - final String path = resourceUri.getPath(); - return new URL(url, resourceUri.getPath()); } }