[英]Ensure Install4j Uses only its bundled jre and never Java found by path
question 题
How can I ensure my install4j installer always finds only its java? 如何确保我的install4j安装程序始终仅找到其Java?
problem 问题
Install4j finds java 1.7 during install which impacts custom code preventing successful installation. Install4j在安装过程中发现Java 1.7,这会影响自定义代码,从而阻止成功安装。 I see found java7 prior to file deployment - ok expected given the JRE hasn't yet been unpacked.
我看到在文件部署之前找到了java7-可以预见,因为JRE尚未解压缩。
evidence I created a simple installer and see the following: 我创建了一个简单的安装程序的证据,并看到以下内容:
BEFORE PATH=/opt/tools/Java/jdk1.7.0_79/bin:... JAVA_HOME=/opt/tools/Java/jdk1.7.0_79 ... ENV [JAVA_HOME] /opt/tools/Java/jdk1.7.0_79 ENV [PATH] /opt/tools/Java/jdk1.7.0_79/bin:...
installer details 安装程序详细信息
envTest.install4j envTest.install4j
echo BEFORE echo PATH=$PATH echo JAVA_HOME=$JAVA_HOME echo Version: java -version
` `
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
Map<String, String> envMap = System.getenv();
SortedMap<String, String> sortedEnvMap = new TreeMap<String, String>(envMap);
Set<String> keySet = sortedEnvMap.keySet();
for (String key : keySet) {
String value = envMap.get(key);
Util.logInfo(this,"ENV [" + key + "] " + value);
}
return true;
Actually, this turned our to be a problem with my custom code. 实际上,这使我们成为自定义代码的问题。 The custom code launches an install4j generated executable via java.
定制代码通过java启动install4j生成的可执行文件。 When launched on command line with wrong java found first, the launcher uses only its own java.
在命令行中首先发现错误的Java时,启动器仅使用其自己的Java。 When launched from my extension it fails.
从我的扩展程序启动后,它将失败。
Solution - set java in my extension: 解决方案-在我的扩展程序中设置Java:
private File getInstalledJREDir() {
return new File(installationDir, "jre");
}
private String addJREToFrontOfPathVar() {
File jreBinDir = new File(getInstalledJREDir(), "bin");
String path = System.getenv().get("PATH");
if (null == path) {
path = jreBinDir.getAbsolutePath();
} else {
path = jreBinDir.getAbsolutePath() + File.pathSeparator + path;
}
return path;
}
/**
* Start Laucnher and block until it starts or timeout reached
* @throws AutoRunException
*/
public void run() throws AutoRunException, IOException, InterruptedException {
notifier.setPhase("Starting Agent");
// Set Directories
File dataDir = new File(installationDir.getParentFile(), "data-agent");
File agentLog = new File(logDir,"agent.log");
if (! isWindows()) {
File agent = new File(installationDir, "bin/launcherExecutable");
CmdExecutor ce = new CmdExecutor(agent, agentLog);
// Ensure our installed JRE found 1st - PLAT-38833
ce.updateEnvironmentVariable("JAVA_HOME", getInstalledJREDir().getAbsolutePath());
ce.updateEnvironmentVariable("PATH", addJREToFrontOfPathVar());
ce.setWorkingDir(installationDir);
ce.setArgLine(String.format("--datadir %s", dataDir.getAbsolutePath()));
notifier.logInfo("Starting " + agent + " with " + ce.getArgLine());
if (! ce.run(true) ) {
throw new AutoRunException("Agent failed to start " + ce.getOutput());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.