From 0d66c7c726e1ede16bcfce1c4fcfdb30a46f06cc Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Mon, 2 Aug 2021 12:21:17 +0200 Subject: Fix alternate JREs missing bin/ directory on java.library.path Exception looks like this: java stack trace: java.lang.UnsatisfiedLinkError: zulu11\bin\fontmanager.dll: Can't find depende nt libraries at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method) at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2442) at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2498) at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2694) at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2648) at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:830) at java.base/java.lang.System.loadLibrary(System.java:1873) at java.desktop/sun.font.FontManagerNativeLibrary$1.run(FontManagerNativeLibrary.java:57) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.desktop/sun.font.FontManagerNativeLibrary.(FontManagerNativeLibrary.java:32) at java.desktop/sun.font.SunFontManager$1.run(SunFontManager.java:279) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.desktop/sun.font.SunFontManager.(SunFontManager.java:275) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:398) at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:82) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74) at java.desktop/sun.java2d.SunGraphicsEnvironment.getFontManagerForSGE(SunGraphicsEnvironment.ja va:189) at java.desktop/sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnviron ment.java:223) at java.desktop/sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnviron ment.java:251) Change-Id: I7a16bb5813d4c089ddb4de34a250280cf6fee137 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119880 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt (cherry picked from commit 48c5ba19e4f4a1ad5a88b5e6f0816c080e1253ec) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119970 Tested-by: Thorsten Behrens Reviewed-by: Thorsten Behrens --- jvmfwk/source/framework.cxx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx index 32120308f932..9684e13107cb 100644 --- a/jvmfwk/source/framework.cxx +++ b/jvmfwk/source/framework.cxx @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include #include @@ -219,6 +221,22 @@ javaFrameworkError jfw_startVM( } assert(pInfo != nullptr); +#ifdef _WIN32 + // Alternative JREs (AdoptOpenJDK, Azul Zulu) are missing the bin/ folder in + // java.library.path. Somehow setting java.library.path accordingly doesn't work, + // but the PATH gets picked up, so add it there. + // Without this hack, some features don't work in alternative JREs. + OUString sPATH; + osl_getEnvironment(OUString("PATH").pData, &sPATH.pData); + OUString sJRELocation; + osl::FileBase::getSystemPathFromFileURL(pInfo->sLocation + "/bin", sJRELocation); + if (sPATH.isEmpty()) + sPATH = sJRELocation; + else + sPATH = sJRELocation + OUStringChar(SAL_PATHSEPARATOR) + sPATH; + osl_setEnvironment(OUString("PATH").pData, sPATH.pData); +#endif // _WIN32 + // create JavaVMOptions array that is passed to the plugin // it contains the classpath and all options set in the //options dialog -- cgit