Java 通过命令行在 Windows 机器上静默安装 JDK 8 和 JRE 8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28043588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 05:30:43  来源:igfitidea点击:

Installing JDK 8 and JRE 8 silently on a Windows machine through command line

javawindowssilent-installer

提问by Dagan Sandler

We want to update the JDK environment on multiple machines, all running windows but different versions (either XP or 7)

我们想在多台机器上更新JDK环境,所有运行的windows但不同版本(XP或7)

For that purpose, I'm now creating a script which will automatically run the correct installer (32/64 bit). I tried running the installer with the following command:

为此,我现在正在创建一个脚本,它将自动运行正确的安装程序(32/64 位)。我尝试使用以下命令运行安装程序:

jdk-8u25-windows-x64.exe /s ADDLOCAL="ToolsFeature,SourceFeature,PublicjreFeature"

jdk-8u25-windows-x64.exe /s ADDLOCAL="ToolsFeature,SourceFeature,PublicjreFeature"

This works fine on a machine with no JDK/JRE 8 installed. However, I am running into a few issues:

这在没有安装 JDK/JRE 8 的机器上工作正常。但是,我遇到了几个问题:

  • If JDK/JRE 8 is already installed, the installer UNINSTALLS both JDK & JRE instead of simply not doing anything (or re-installing)
  • If a reboot is required it is forcefully performed automatically, and I need to avoid that as there are other actions I need to perform in the script after the installation completes.
  • There is no VERBOSE mode / log file to indicate what the installer is actually doing
  • 如果已经安装了 JDK/JRE 8,安装程序会卸载 JDK 和 JRE,而不是简单地不做任何事情(或重新安装)
  • 如果需要重新启动,它会自动强制执行,我需要避免这种情况,因为在安装完成后我需要在脚本中执行其他操作。
  • 没有详细模式/日志文件来指示安装程序实际在做什么

I have looked at these sources:

我查看了这些来源:

but they seem lacking and very confusing as to what will give me the wanted result.

但他们似乎缺乏并且非常困惑什么会给我想要的结果。

回答by odoepner

I would tackle JDK and JRE separately:

我将分别处理 JDK 和 JRE:

The JDKdoes not depend on registry entries or whatever else the installer exe does. So install the JDK - withoutPublic JRE - on just onemachine using

JDK不依赖于注册表项或任何其他安装程序exe文件一样。所以安装JDK -没有公共JRE - 在台机器上使用

jdk-8u25-windows-x64.exe /s ADDLOCAL="ToolsFeature,SourceFeature"

Then you can simply zip up the resulting installation, copy and unzip it to other machines of the same OS type.

然后您可以简单地压缩生成的安装,将其复制并解压缩到相同操作系统类型的其他机器上。

The JREinstaller (separate download from Oracle) can be run with options and config file as documented here : http://docs.oracle.com/javase/8/docs/technotes/guides/install/windows_installer_options.html

JRE安装程序(从Oracle单独下载)可以选择和配置文件运行如下记载:http://docs.oracle.com/javase/8/docs/technotes/guides/install/windows_installer_options.html

Assuming the config is in the same directory as the installer exe, the option INSTALLCFG="%cd%\jre-install-options.cfg"can be used. Otherwise, a full path is required to the config file (INSTALLCFG="c:\path\to\jre-install-options.cfg"). So, something like this (with log file and assuming the config file is in the same directory of the exe):

假设 config 与安装程序 exe 位于同一目录中,则INSTALLCFG="%cd%\jre-install-options.cfg"可以使用该选项。否则,需要配置文件的完整路径 (INSTALLCFG="c:\path\to\jre-install-options.cfg")。所以,像这样(带有日志文件并假设配置文件在 exe 的同一目录中):

jre-8-windows-i586.exe INSTALLCFG="%cd%\jre-install-options.cfg" /s /L C:\TMP\jre-install.log

It seems that the following jre-install-options.txt might work for you:

似乎以下 jre-install-options.txt 可能适合您:

INSTALL_SILENT=Enable
REBOOT=Disable
STATIC=Enable

The config file options are listed here: http://docs.oracle.com/javase/8/docs/technotes/guides/install/config.html

此处列出了配置文件选项:http: //docs.oracle.com/javase/8/docs/technotes/guides/install/config.html

The meaning of the last line is explained here : http://docs.oracle.com/javase/8/docs/technotes/guides/install/windows_installer_options.html#static_installation

最后一行的含义在这里解释:http: //docs.oracle.com/javase/8/docs/technotes/guides/install/windows_installer_options.html#static_installation

回答by Klodi

For JRE silent installation :

对于 JRE 静默安装:

start /wait msiexec /i "%~ java8.40x64.msi " JU=0 JAVAUPDATE=0 AUTOUPDATECHECK=0 RebootYesNo=No WEB_JAVA=1 /q

start /wait msiexec /i "%~ java8.40x64.msi " JU=0 JAVAUPDATE=0 AUTOUPDATECHECK=0 RebootYesNo=No WEB_JAVA=1 /q

You can see full post here.

你可以在这里看到完整的帖子。

回答by Jitendra

I was facing similar issue with /s option. I i found a jdk bug https://bugs.openjdk.java.net/browse/JDK-8033364. I seems they have removed support for help or s. Try /qn it worked for me

我在使用 /s 选项时遇到了类似的问题。我发现了一个 jdk 错误https://bugs.openjdk.java.net/browse/JDK-8033364。我似乎他们已经取消了对 help 或 s 的支持。试试 /qn 对我有用

jdk-8u92-windows-x64.exe /qn

jdk-8u92-windows-x64.exe /qn

回答by Todd Lyons

It seems there are constant changes to the supported commandline options. For the latest 8 Update 131, I had to abandon all msiexec style options because none of them worked. I used the documentation for the java version I downloaded to construct switches to the installer. As shown in answers above, the config file options can be passed to the installer on the commandline. The final command that I used in Packer to install Java on a Win2016 Server ami was:

似乎支持的命令行选项不断变化。对于最新的 8 Update 131,我不得不放弃所有 msiexec 样式选项,因为它们都不起作用。我使用下载的 java 版本的文档来构建安装程序的开关。如上面的答案所示,可以在命令行上将配置文件选项传递给安装程序。我在 Packer 中用于在 Win2016 Server ami 上安装 Java 的最后一个命令是:

Start-Process 'C:\Windows\Temp\jre-8u131-windows-x64.exe' `
  -ArgumentList 'INSTALL_SILENT=Enable REBOOT=Disable SPONSORS=Disable' `
  -Wait -PassThru

This command also adds Java to the system path by default, however not in the one it installs. Open a new powershell shell and it will be in the path for that shell (Inspect with $env.path)

默认情况下,此命令还将 Java 添加到系统路径中,但不在它安装的路径中。打开一个新的 powershell shell,它将在该 shell 的路径中(Inspect with $env.path

Sources of truth:

真相来源:

http://docs.oracle.com/javase/8/docs/technotes/guides/install/windows_installer_options.htmlhttp://docs.oracle.com/javase/8/docs/technotes/guides/install/config.html#table_config_file_options

http://docs.oracle.com/javase/8/docs/technotes/guides/install/windows_installer_options.html http://docs.oracle.com/javase/8/docs/technotes/guides/install/config.html #table_config_file_options