17

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 (i.e. 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?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
mmo
  • 3,897
  • 11
  • 42
  • 63
  • 3
    *"On my development machine I always have to install Java 6 and Java 7 and I have to install each JDK"* I'd argue that you are mistaken. Why do you ***think*** you need two versions of the SDK installed? What benefit or ability does it provide? BTW - leave sigs. out of questions - they are noise. – Andrew Thompson Mar 08 '13 at 11:06
  • @AndrewThompson "*I have to install each JDK in both, the 32 and 64 bit version, **for testing purposes***" – assylias Mar 08 '13 at 11:28
  • 3
    @assylias My bad. -- OK. You don't need two JDKs, but one JDK (for compiling) and two JREs (for testing). – Andrew Thompson Mar 08 '13 at 11:37
  • I think this is a different discussion. I also use misc. tools, that require JDKs being installed. Some of them are 32 bit, some 64. Maybe I wouldn't need ALL of them, but at least 2 or 3 different ones and so I simply install ALL variants, when there is an update. But, please, I am really more interested in an answer to my original question. – mmo Mar 08 '13 at 14:44
  • looks likean item for oracle bug parade to add as future feature. maybe u can try opensdk? – tgkprog Mar 12 '13 at 12:29

8 Answers8

13

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

Verhagen
  • 3,885
  • 26
  • 36
Software Craftsman
  • 2,999
  • 2
  • 31
  • 47
  • 1
    JDK 8 Silent Install http://docs.oracle.com/javase/8/docs/technotes/guides/install/windows_jdk_install.html#CHDHHBDD – SimplyInk Mar 21 '17 at 02:50
3

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

Matt
  • 1,300
  • 2
  • 14
  • 31
  • Alas, that doesn't seem to work. When calling the command line as shown in the referenced article I always get a popup of Windows Installer apparently trying to teach me, that I specified some options wrongly. But the options listed refer to an .msi file (which presumably is contained in the jdk.exe, but which is not directly available when executing the command...). – mmo Apr 28 '13 at 10:02
2

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.

Gili
  • 86,244
  • 97
  • 390
  • 689
  • With upgrade 7u51 it now also doesn't work anymore with the JRE-installer. Both, the JRE and the JDK installer, when started via command line using .exe /s INSTALLDIR="" only pop up an msi-installer error dialog... :-( – mmo Jan 21 '14 at 23:48
  • `.exe /passive INSTALLDIR=""` works for me with 7u79. – Knyri Jul 08 '15 at 20:07
2

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.

uk4sx
  • 1,101
  • 1
  • 8
  • 11
  • +1 for using junctions (reparse points) on Windows. I do that with my Ruby and Python versions and simple batch files for version management.. Not enough people know they exist on Windows.. – kodybrown Apr 24 '15 at 21:07
2

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!

1

Try: jdk-7u2-windows-i586.exe /s INSTALLDIR=\"C:\Program Files\JAVA\JDK\"

  • That's the same suggestion as above and - as I already wrote in the comment to it - it does not work but brings up some error dialog of the MSI installer... – mmo Jun 24 '13 at 07:05
0

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.x.y\jdk.x.y.z.msi
  3. run msiexec /i jdkx.y.z.msi /passive INSTALLDIR:c:\pippo
Tommaso
  • 520
  • 1
  • 6
  • 20
0

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
acgbox
  • 312
  • 2
  • 13