How to silently install Java JDK into a specific directory on windows
Asked Answered
C

8

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?

Concealment answered 8/3, 2013 at 11:3 Comment(5)
"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.Rolfston
@AndrewThompson "I have to install each JDK in both, the 32 and 64 bit version, for testing purposes"Touchwood
@Touchwood My bad. -- OK. You don't need two JDKs, but one JDK (for compiling) and two JREs (for testing).Rolfston
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.Concealment
looks likean item for oracle bug parade to add as future feature. maybe u can try opensdk?Precinct
T
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

Triadelphous answered 26/8, 2015 at 11:19 Comment(1)
JDK 8 Silent Install docs.oracle.com/javase/8/docs/technotes/guides/install/…Lastminute
P
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...

Palaestra answered 26/4, 2013 at 18:23 Comment(1)
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...).Concealment
G
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.

Galvani answered 16/9, 2013 at 20:54 Comment(2)
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 <installer>.exe /s INSTALLDIR="<dir>" only pop up an msi-installer error dialog... :-(Concealment
<installer>.exe /passive INSTALLDIR="<dir>" works for me with 7u79.Coddle
D
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.

Doelling answered 17/7, 2014 at 7:56 Comment(1)
+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..Bildungsroman
W
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!

Wolverine answered 25/2, 2015 at 20:18 Comment(0)
A
1

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

Abampere answered 19/6, 2013 at 21:41 Comment(1)
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...Concealment
R
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
Ranchod answered 2/7, 2014 at 9:7 Comment(0)
S
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
Seminole answered 16/1, 2019 at 17:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.