简体   繁体   English

如何将Java JDK静默安装到Windows上的特定目录中

[英]How to silently install Java JDK into a specific directory on windows

On my development machine I always have to install Java 6 and Java 7 and I have to install each JDK in both, the 32 and 64 bit version, for testing purposes. 在我的开发机器上,我总是需要安装Java 6 Java 7,我必须在32位和64位版本中安装每个JDK,以便进行测试。 Since the frequency of Java updates seems to be getting more and more ridiculous (twice per week by now?) each update requires me to un- and then re-install 4 JDKs. 由于Java更新的频率似乎变得越来越荒谬(现在每周两次?)每次更新都要求我取消然后重新安装4个 JDK。 So this is getting really quite annoying and I would thus like to script this entire process. 所以这真的很烦人,因此我想编写整个过程的脚本。

My problem is, that by default each JDK versions installs into a directory-path that contains the update-number (default: "C:\\Program Files\\Java\\jdk1.6.0_<update-nr>\\"). 我的问题是,默认情况下,每个JDK版本都安装到包含update-number的目录路径中(默认值:“C:\\ Program Files \\ Java \\ jdk1.6.0_ <update-nr> \\”)。 To spare me from having to adapt tons of build-scripts I always manually strip the trailing "_<update-nr>" from the installation path and always install into the same "C:\\Program Files\\Java\\jdk1.6.0" or "C:\\Program Files\\Java\\jdk1.7.0", resp., for the 64-bit versions and into C:\\Program Files (x86)\\Java\\jdk1.6.0" or "C:\\Program Files (x86)\\Java\\jdk1.7.0", resp., for the 32-bit versions. 为了避免我不得不调整大量的构建脚本,我总是手动从安装路径中删除尾随的“_ <update-nr>”并始终安装到相同的“C:\\ Program Files \\ Java \\ jdk1.6.0”或“C:\\ Program Files \\ Java \\ jdk1.7.0”,分别为64位版本和C:\\ Program Files(x86)\\ Java \\ jdk1.6.0“或”C:\\ Program Files(x86) \\ Java \\ jdk1.7.0“,对于32位版本,分别为。

While I found out, how to specify the installation directory for a JRE installer (ie the Java runtime): 我发现了,如何为JRE安装程序(即Java运行时)指定安装目录:

<jre-installfile>.exe [/s] [INSTALLDIR=<drive>:\<JRE_install_path>] 
    [STATIC=1] [WEB_JAVA=0/1] [WEB_JAVA_SECURITY_LEVEL=VH/H/M/L]

I did not yet find a similar description how to specify the installation directory for the JDK installer. 我还没有找到类似的描述如何指定JDK安装程序的安装目录。

Does anyone know if and how one can specify the install path for the JDK installer, so that one can direct a silent JDK installation into a specific installation directory? 有谁知道是否以及如何指定JDK安装程序的安装路径,以便可以将静默JDK安装指向特定的安装目录?

I could successfully install both x64 and x86 versions of JDK 8 update 60 including a public JRE with these commands: 我可以使用以下命令成功安装包含公共JRE的x64和x86版本的JDK 8 update 60:

Here JDK 1.8.60 (x86) with source code is going to C:\\Java\\x86\\jdk1.8.0_60 and JRE to C:\\Java\\x86\\jre1.8.0_60 : 这里带有源代码的JDK 1.8.60(x86)将转到C:\\Java\\x86\\jdk1.8.0_60 ,JRE转到C:\\Java\\x86\\jre1.8.0_60

jdk-8u60-windows-i586.exe /s ADDLOCAL="ToolsFeature,SourceFeature,PublicjreFeature" INSTALLDIR=C:\Java\x86\jdk1.8.0_60 /INSTALLDIRPUBJRE=C:\Java\x86\jre1.8.0_60

In a similar way, JDK 1.8.60 (x64) with source code is going to C:\\Java\\x64\\jdk1.8.0_60 and JRE to C:\\Java\\x64\\jre1.8.0_60 : 以类似的方式,带源代码的JDK 1.8.60(x64)将转到C:\\Java\\x64\\jdk1.8.0_60 ,JRE转到C:\\Java\\x64\\jre1.8.0_60

jdk-8u60-windows-x64.exe /s ADDLOCAL="ToolsFeature,SourceFeature,PublicjreFeature" INSTALLDIR=C:\Java\x64\jdk1.8.0_60 /INSTALLDIRPUBJRE=C:\Java\x64\jre1.8.0_60

See Oracle JRE installer options 请参阅Oracle JRE安装程序选项

One approach to avoid rewriting directories in scripts is to use symlinks (junctions on NTFS). 避免在脚本中重写目录的一种方法是使用符号链接(NTFS上的联结)。 First, download the junction utility from SysInternals here: http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx then unzip, copy to some directory on the PATH, and run once to accept the licence. 首先,从SysInternals下载结点实用程序: http//technet.microsoft.com/en-us/sysinternals/bb896768.aspx然后解压缩,复制到PATH上的某个目录,然后运行一次以接受许可证。

Then you can create symlinks easily: junction "C:\\Program Files\\Java\\jdk1.6.0" "C:\\Program Files\\Java\\jdk1.6.0_37" junction "C:\\Program Files (x86)\\Java\\jdk1.6.0" "C:\\Program Files (x86)\\Java\\jdk1.6.0_37" 然后,您可以轻松创建符号链接: junction "C:\\Program Files\\Java\\jdk1.6.0" "C:\\Program Files\\Java\\jdk1.6.0_37" junction "C:\\Program Files (x86)\\Java\\jdk1.6.0" "C:\\Program Files (x86)\\Java\\jdk1.6.0_37"

To delete some symlink: junction -d "C:\\Program Files\\Java\\jdk1.6.0" 删除一些符号链接: junction -d "C:\\Program Files\\Java\\jdk1.6.0"

You can also use mklink ( http://technet.microsoft.com/en-us/library/cc753194.aspx ) instead (and del for removal), but I prefer the simplicity and clarity of junction. 您也可以使用mklink( http://technet.microsoft.com/en-us/library/cc753194.aspx )(和删除del),但我更喜欢结点的简单性和清晰度。

I just found this article while searching... it specifies a parameter for INSTALLDIR. 我刚刚搜索时发现了这篇文章......它为INSTALLDIR指定了一个参数。

http://makeitfaster.wordpress.com/2011/03/25/java-jdk-silent-install-on-windows/ http://makeitfaster.wordpress.com/2011/03/25/java-jdk-silent-install-on-windows/

jdk-7u2-windows-i586.exe /s ADDLOCAL="ToolsFeature,SourceFeature" INSTALLDIR="%CD%\jdk7u2"

I unfortunately had already installed on my dev machine, so i couldn't test... 我很遗憾已经在我的开发机器上安装了,所以我无法测试......

试试:jdk-7u2-windows-i586.exe / s INSTALLDIR = \\“C:\\ Program Files \\ JAVA \\ JDK \\”

I just discovered a regression in the JDK7 installer that causes it to ignore INSTALLDIR . 我刚刚在JDK7安装程序中发现了一个回归,导致它忽略INSTALLDIR The last correct version is update 21. 最后一个正确的版本是更新21。

I have filed a bug report and will let you know once Oracle replies. 我已经提交了一份错误报告,并会在Oracle回复后通知您。

UPDATE : It turns out that this was caused by an corrupt (incomplete) JDK installation. 更新 :事实证明这是由一个损坏的(不完整的)JDK安装引起的。 Once I uninstalled this version (Add/Remove Programs) the new installation ran just fine. 卸载此版本(添加/删除程序)后,新安装运行正常。

This is the way that works for me for JDK_7u55. 这是适用于JDK_7u55的方式。 I opted to have the JRE installed too: 我选择安装JRE:

PowerShell Commands PowerShell命令

$strJavaInstallExe=<Your JDK executable>
$strJavaInstallDir=<The directory you want the JDK and JRE to install to>

$cmdInstallJava=$strJavaInstallExe+' /passive /log "'+$strJavaInstallDir+'\install.log" ADDLOCAL="ToolsFeature,SourceFeature,PublicjreFeature" INSTALLDIR="'+$strJavaInstallDir+'" INSTALLDIRPUBJRE="'+$strJavaInstallDir+'"'

Invoke-Expression $cmdInstallJava

Hope this helps! 希望这可以帮助!

EDIT - easier way 编辑 - 更简单的方法

Execute jdk-7u60-windows-x64.exe /passive /log install.log INSTALLDIR:c:\\pippo 执行jdk-7u60-windows-x64.exe /passive /log install.log INSTALLDIR:c:\\pippo

Works with 7u45 and 7u60 适用于7u45和7u60

OLD answer 老答案

The exe contains the msi installer. exe包含msi安装程序。 To extract is (for sure there are more elegant methods, but I know only this one) 提取是(肯定有更优雅的方法,但我只知道这个)

  1. Run the exe manually - you need to do it only the first time, to convert it to an msi 手动运行exe - 您只需要第一次执行它,将其转换为msi
  2. Grab the msi (and all other.cab file) from C:\\Users\\AppData\\LocalLow\\Sun\\Java\\jdx.xy\\jdk.xyzmsi 从C:\\ Users \\ AppData \\ LocalLow \\ Sun \\ Java \\ jdx.xy \\ jdk.xyzmsi抓取msi(和所有other.cab文件)
  3. run msiexec /i jdkx.yzmsi /passive INSTALLDIR:c:\\pippo 运行msiexec /i jdkx.yzmsi /passive INSTALLDIR:c:\\pippo

file jreinstall.bat (example: storage in desktop) (replace jre for jdk) file jreinstall.bat(例如:桌面存储)(替换jdk的jre)

@echo off
start /w %UserProfile%\Desktop\jre-8u65-windows-x64.exe /s
setx JAVA_HOME "C:\Program Files\Java\jre1.8.0_65"
exit

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

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