简体   繁体   中英

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. 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. 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>\\"). 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.

While I found out, how to specify the installation directory for a JRE installer (ie the Java runtime):

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

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?

I could successfully install both x64 and x86 versions of JDK 8 update 60 including a public JRE with these commands:

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

One approach to avoid rewriting directories in scripts is to use symlinks (junctions on 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.

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"

To delete some symlink: 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.

I just found this article while searching... it specifies a parameter for INSTALLDIR.

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 . The last correct version is update 21.

I have filed a bug report and will let you know once Oracle replies.

UPDATE : It turns out that this was caused by an corrupt (incomplete) JDK installation. 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. I opted to have the JRE installed too:

PowerShell Commands

$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

Works with 7u45 and 7u60

OLD answer

The exe contains the msi installer. 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
  2. Grab the msi (and all other.cab file) from C:\\Users\\AppData\\LocalLow\\Sun\\Java\\jdx.xy\\jdk.xyzmsi
  3. run msiexec /i jdkx.yzmsi /passive INSTALLDIR:c:\\pippo

file jreinstall.bat (example: storage in desktop) (replace jre for jdk)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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