简体   繁体   English

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

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

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).为此,我现在正在创建一个脚本,它将自动运行正确的安装程序(32/64 位)。 I tried running the installer with the following command:我尝试使用以下命令运行安装程序:

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

This works fine on a machine with no JDK/JRE 8 installed.这在没有安装 JDK/JRE 8 的机器上工作正常。 However, I am running into a few issues:但是,我遇到了几个问题:

  • If JDK/JRE 8 is already installed, the installer UNINSTALLS both JDK & JRE instead of simply not doing anything (or re-installing)如果已经安装了 JDK/JRE 8,安装程序会卸载 JDK 和 JRE,而不是简单地不做任何事情(或重新安装)
  • 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没有详细模式/日志文件来指示安装程序实际在做什么

I have looked at these sources:我查看了这些来源:

but they seem lacking and very confusing as to what will give me the wanted result.但他们似乎缺乏并且非常困惑什么会给我想要的结果。

I would tackle JDK and JRE separately:我将分别处理 JDK 和 JRE:

The JDK does not depend on registry entries or whatever else the installer exe does. JDK不依赖于注册表项或安装程序 exe 所做的任何其他事情。 So install the JDK - without Public JRE - on just one machine using所以安装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 JRE installer (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.假设配置与安装程序 exe 位于同一目录中,则可以使用选项INSTALLCFG="%cd%\\jre-install-options.cfg" Otherwise, a full path is required to the config file (INSTALLCFG="c:\\path\\to\\jre-install-options.cfg").否则,需要配置文件的完整路径 (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):所以,像这样(带有日志文件并假设配置文件在 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

I was facing similar issue with /s option.我在使用 /s 选项时遇到了类似的问题。 I i found a jdk bug https://bugs.openjdk.java.net/browse/JDK-8033364 .我发现了一个 jdk 错误https://bugs.openjdk.java.net/browse/JDK-8033364 I seems they have removed support for help or s.我似乎他们已经取消了对 help 或 s 的支持。 Try /qn it worked for me试试 /qn 对我有用

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

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.对于最新的 8 Update 131,我不得不放弃所有 msiexec 样式选项,因为它们都不起作用。 I used the documentation for the java version I downloaded to construct switches to the installer.我使用下载的 java 版本的文档来构建安装程序的开关。 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:我在 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.默认情况下,此命令还将 Java 添加到系统路径中,但不在它安装的路径中。 Open a new powershell shell and it will be in the path for that shell (Inspect with $env.path )打开一个新的 powershell shell,它将位于该 shell 的路径中(使用$env.path检查)

Sources of truth:真相来源:

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 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

For JRE silent installation :对于 JRE 静默安装:

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 .你可以在这里看到完整的帖子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM