8267598: jpackage removes system libraries from java.library.path

Reviewed-by: almatvee, asemenyuk
This commit is contained in:
Andy Herrick 2021-06-03 19:02:11 +00:00
parent 52d8215a1e
commit af3df6300e
9 changed files with 33 additions and 12 deletions

View File

@ -66,6 +66,7 @@ void launchApp() {
appLauncher
.setImageRoot(appImageRoot)
.setAppDir(FileUtils::mkpath() << appImageRoot << _T("lib/app"))
.setLibEnvVariableName(_T("LD_LIBRARY_PATH"))
.setDefaultRuntimePath(FileUtils::mkpath() << appImageRoot
<< _T("lib/runtime"));
} else {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -56,6 +56,7 @@ void initJvmLauncher() {
// add backup - older version such as JDK11 have it in jli sub-dir
.addJvmLibName(_T("Contents/Home/lib/jli/libjli.dylib"))
.setAppDir(FileUtils::mkpath() << appImageRoot << _T("Contents/app"))
.setLibEnvVariableName(_T("DYLD_LIBRARY_PATH"))
.setDefaultRuntimePath(FileUtils::mkpath() << appImageRoot
<< _T("Contents/runtime"))
.createJvmLauncher();

View File

@ -112,14 +112,14 @@ Jvm* AppLauncher::createJvmLauncher() const {
PropertyName::arguments, args);
}
SysInfo::setEnvVariable(libEnvVarName, SysInfo::getEnvVariable(
std::nothrow, libEnvVarName) + _T(";") + appDirPath);
std::unique_ptr<Jvm> jvm(new Jvm());
(*jvm)
.setPath(findJvmLib(cfgFile, defaultRuntimePath, jvmLibNames))
.addArgument(launcherPath)
.addArgument(_T("-Djava.library.path=")
+ appDirPath + FileUtils::pathSeparator
+ FileUtils::dirname(launcherPath));
.addArgument(launcherPath);
if (initJvmFromCmdlineOnly) {
tstring_array::const_iterator argIt = args.begin();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -50,6 +50,11 @@ public:
return *this;
}
AppLauncher& setLibEnvVariableName(const tstring& v) {
libEnvVarName = v;
return *this;
}
AppLauncher& setInitJvmFromCmdlineOnly(bool v) {
initJvmFromCmdlineOnly = v;
return *this;
@ -69,6 +74,7 @@ private:
tstring launcherPath;
tstring defaultRuntimePath;
tstring appDirPath;
tstring libEnvVarName;
tstring imageRoot;
tstring_array jvmLibNames;
bool initJvmFromCmdlineOnly;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -83,10 +83,16 @@ namespace SysInfo {
tstring getEnvVariable(const std::nothrow_t&, const tstring& name,
const tstring& defValue=tstring());
/**
* Sets the value of environment variable with the given name to the given value.
*/
void setEnvVariable(const tstring& name, const tstring& value);
/**
* Returns 'true' if environment variable with the given name is set.
*/
bool isEnvVariableSet(const tstring& name);
}
#endif // SYSINFO_H

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -55,6 +55,10 @@ bool isEnvVariableSet(const tstring& name) {
return ::getenv(name.c_str()) != 0;
}
void setEnvVariable(const tstring& name, const tstring& value) {
::setenv(name.c_str(), value.c_str(), 1);
}
int argc = 0;
char** argv = 0;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -145,6 +145,7 @@ void launchApp() {
.setImageRoot(appImageRoot)
.addJvmLibName(_T("bin\\jli.dll"))
.setAppDir(FileUtils::mkpath() << appImageRoot << _T("app"))
.setLibEnvVariableName(_T("PATH"))
.setDefaultRuntimePath(FileUtils::mkpath() << appImageRoot
<< _T("runtime"))
.createJvmLauncher());

View File

@ -122,6 +122,10 @@ void setEnvVariable(const tstring& name, const tstring& value)
<< name << ", " << value
<< ") failed", SetEnvironmentVariable));
}
if (0 != _tputenv_s(name.c_str(), value.c_str())) {
JP_THROW(tstrings::any() << "_tputenv_s(" << name << ", " << value << ") failed: " << lastCRTError());
}
}
tstring getCurrentModulePath()

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -43,8 +43,6 @@ namespace SysInfo {
// Returns handle of the current module (exe or dll).
// The function assumes this code is statically linked to the module.
HMODULE getCurrentModuleHandle();
void setEnvVariable(const tstring& name, const tstring& value);
}