Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.
/ jfx11u Public archive

Commit 2f2a07a

Browse files
8281089: JavaFX built with VS2019 and jlinked into JDK 11.x fails to start
Backport-of: e74cbe8b9563a1ab1a21290aa125579bdaa2f29f
1 parent ddda6e1 commit 2f2a07a

File tree

2 files changed

+86
-51
lines changed

2 files changed

+86
-51
lines changed

build.gradle

+30-17
Original file line numberDiff line numberDiff line change
@@ -5825,13 +5825,6 @@ compileTargets { t ->
58255825
def standaloneSdkDir = "${rootProject.buildDir}/${standaloneSdkDirName}"
58265826
def standaloneLegalDir = "${standaloneSdkDir}/legal"
58275827

5828-
def excludeNativeLibs = []
5829-
if (IS_WINDOWS) {
5830-
// List of duplicate Microsoft DLLs to exclude
5831-
excludeNativeLibs += targetProperties.VS2017DLLNames
5832-
excludeNativeLibs += targetProperties.WinSDKDLLNames
5833-
}
5834-
58355828
moduleProjList.each { project ->
58365829
def moduleName = project.ext.moduleName
58375830
def buildDir = project.buildDir
@@ -5840,9 +5833,36 @@ compileTargets { t ->
58405833
def srcLibDir = "${buildDir}/${platformPrefix}module-lib"
58415834
def srcLegalDir = "${standaloneLegalDir}/${moduleName}"
58425835

5836+
def jmodLibDir = srcLibDir
5837+
if (IS_WINDOWS) {
5838+
jmodLibDir = "${srcLibDir}-jmod"
5839+
}
5840+
58435841
def jmodName = "${moduleName}.jmod"
58445842
def jmodFile = "${jmodsDir}/${jmodName}"
5845-
def jmodTask = project.task("jmod$t.capital", group: "Build", dependsOn: sdk) {
5843+
5844+
// On Windows, copy the native libraries in the jmod image
5845+
// to a "javafx" subdir to avoid conflicting with the Microsoft
5846+
// DLLs that are shipped with the JDK
5847+
def jmodCopyLibTask = project.task("jmodCopyLib$t.capital", type: Copy, dependsOn: sdk) {
5848+
enabled = IS_WINDOWS
5849+
5850+
group = "Basic"
5851+
description = "copied Windows DLLs into javafx subdir for jmods"
5852+
5853+
into jmodLibDir
5854+
5855+
from (srcLibDir) {
5856+
exclude("*.dll")
5857+
}
5858+
5859+
from (srcLibDir) {
5860+
include("*.dll")
5861+
into("javafx")
5862+
}
5863+
}
5864+
5865+
def jmodTask = project.task("jmod$t.capital", group: "Build", dependsOn: [sdk, jmodCopyLibTask]) {
58465866
doLast {
58475867
mkdir jmodsDir
58485868
delete(jmodFile);
@@ -5852,16 +5872,9 @@ compileTargets { t ->
58525872
args("--class-path")
58535873
args(srcClassesDir)
58545874
// Not all modules have a "lib" dir
5855-
if (file(srcLibDir).isDirectory()) {
5875+
if (file(jmodLibDir).isDirectory()) {
58565876
args("--libs")
5857-
args(srcLibDir)
5858-
}
5859-
// Exclude duplicate native libs from javafx.graphics.jmod
5860-
if (moduleName == "javafx.graphics") {
5861-
excludeNativeLibs.each { name ->
5862-
args("--exclude")
5863-
args(name)
5864-
}
5877+
args(jmodLibDir)
58655878
}
58665879
args("--legal-notices")
58675880
args(srcLegalDir)

modules/javafx.graphics/src/main/java/com/sun/glass/utils/NativeLibLoader.java

+56-34
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public static synchronized void loadLibrary(String libname, List<String> depende
6666

6767
private static boolean verbose = false;
6868

69-
private static boolean usingModules = false;
7069
private static File libDir = null;
7170
private static String libPrefix = "";
7271
private static String libSuffix = "";
@@ -112,8 +111,9 @@ private static String[] initializePath(String propname) {
112111

113112
private static void loadLibraryInternal(String libraryName, List<String> dependencies, Class caller) {
114113
// The search order for native library loading is:
115-
// - try to load the native library from the same folder as this jar
116-
// (only on non-modular builds)
114+
// - try to load the native library from either ${java.home}
115+
// (for jlinked javafx modules) or from the same folder as
116+
// this jar (if using modular jars)
117117
// - if the native library comes bundled as a resource it is extracted
118118
// and loaded
119119
// - the java.library.path is searched for the library in definition
@@ -126,7 +126,7 @@ private static void loadLibraryInternal(String libraryName, List<String> depende
126126
// since it isn't applicable to Jigsaw.
127127
loadLibraryFullPath(libraryName);
128128
} catch (UnsatisfiedLinkError ex) {
129-
if (verbose && !usingModules) {
129+
if (verbose) {
130130
System.err.println("WARNING: " + ex);
131131
}
132132

@@ -322,51 +322,73 @@ static byte[] calculateCheckSum(File file) {
322322
}
323323

324324

325+
private static File libDirForJRT() {
326+
String javaHome = System.getProperty("java.home");
327+
328+
if (javaHome == null || javaHome.isEmpty()) {
329+
throw new UnsatisfiedLinkError("Cannot find java.home");
330+
}
331+
332+
// Set the native directory based on the OS
333+
String osName = System.getProperty("os.name");
334+
String relativeDir = null;
335+
if (osName.startsWith("Windows")) {
336+
relativeDir = "bin/javafx";
337+
} else if (osName.startsWith("Mac")) {
338+
relativeDir = "lib";
339+
} else if (osName.startsWith("Linux")) {
340+
relativeDir = "lib";
341+
}
342+
343+
// Location of native libraries relative to java.home
344+
return new File(javaHome + "/" + relativeDir);
345+
}
346+
347+
private static File libDirForJarFile(String classUrlString) throws Exception {
348+
// Strip out the "jar:" and everything after and including the "!"
349+
String tmpStr = classUrlString.substring(4, classUrlString.lastIndexOf('!'));
350+
// Strip everything after the last "/" or "\" to get rid of the jar filename
351+
int lastIndexOfSlash = Math.max(tmpStr.lastIndexOf('/'), tmpStr.lastIndexOf('\\'));
352+
353+
// Set the native directory based on the OS
354+
String osName = System.getProperty("os.name");
355+
String relativeDir = null;
356+
if (osName.startsWith("Windows")) {
357+
relativeDir = "../bin";
358+
} else if (osName.startsWith("Mac")) {
359+
relativeDir = ".";
360+
} else if (osName.startsWith("Linux")) {
361+
relativeDir = ".";
362+
}
363+
364+
// Location of native libraries relative to jar file
365+
String libDirUrlString = tmpStr.substring(0, lastIndexOfSlash)
366+
+ "/" + relativeDir;
367+
return new File(new URI(libDirUrlString).getPath());
368+
}
369+
325370
/**
326-
* Load the native library from the same directory as the jar file
327-
* containing this class.
371+
* Load the native library either from the same directory as the jar file
372+
* containing this class, or from the Java runtime.
328373
*/
329374
private static void loadLibraryFullPath(String libraryName) {
330375
try {
331-
if (usingModules) {
332-
throw new UnsatisfiedLinkError("ignored");
333-
}
334376
if (libDir == null) {
335377
// Get the URL for this class, if it is a jar URL, then get the
336378
// filename associated with it.
337379
String theClassFile = "NativeLibLoader.class";
338380
Class theClass = NativeLibLoader.class;
339381
String classUrlString = theClass.getResource(theClassFile).toString();
340382
if (classUrlString.startsWith("jrt:")) {
341-
// Suppress warning messages
342-
usingModules = true;
343-
throw new UnsatisfiedLinkError("ignored");
344-
}
345-
if (!classUrlString.startsWith("jar:file:") || classUrlString.indexOf('!') == -1) {
383+
libDir = libDirForJRT();
384+
} else if (classUrlString.startsWith("jar:file:") && classUrlString.indexOf('!') > 0) {
385+
libDir = libDirForJarFile(classUrlString);
386+
} else {
346387
throw new UnsatisfiedLinkError("Invalid URL for class: " + classUrlString);
347388
}
348-
// Strip out the "jar:" and everything after and including the "!"
349-
String tmpStr = classUrlString.substring(4, classUrlString.lastIndexOf('!'));
350-
// Strip everything after the last "/" or "\" to get rid of the jar filename
351-
int lastIndexOfSlash = Math.max(tmpStr.lastIndexOf('/'), tmpStr.lastIndexOf('\\'));
352-
353-
// Set the native directory based on the OS
354-
String osName = System.getProperty("os.name");
355-
String relativeDir = null;
356-
if (osName.startsWith("Windows")) {
357-
relativeDir = "../bin";
358-
} else if (osName.startsWith("Mac")) {
359-
relativeDir = ".";
360-
} else if (osName.startsWith("Linux")) {
361-
relativeDir = ".";
362-
}
363-
364-
// Location of native libraries relative to jar file
365-
String libDirUrlString = tmpStr.substring(0, lastIndexOfSlash)
366-
+ "/" + relativeDir;
367-
libDir = new File(new URI(libDirUrlString).getPath());
368389

369390
// Set the lib prefix and suffix based on the OS
391+
String osName = System.getProperty("os.name");
370392
if (osName.startsWith("Windows")) {
371393
libPrefix = "";
372394
libSuffix = ".dll";

0 commit comments

Comments
 (0)