Changes

Jump to: navigation, search

Java

16,318 bytes added, 18:10, 20 April 2015
Java Runtime Environment (JRE) 8: Added a PowerShell script to remove other JRE 8 versions. In an attempt to prevent this section turning into a mess, did extensive reorganization & added explanations.
=Java Runtime Environment (JRE) 8=
Get the offline-installers from http://www.oracle.com/technetwork/java/javase/downloads/index.html.
Extract the MSIOracle, in its infinite wisdom, [https://bugs.openjdk.java.net/browse/JDK-files8073009?focusedCommentId=13612776&page=com.atlassian.jira.plugin.system.issuetabpanels:*Run the installer on a testcomment-computer*Copy the MSItabpanel#comment-file 13612776 removed patch-in-place] from C:\Users\username\AppData\LocalLow\Sun\Java 8u20; despite a comment in [http://www.oracle.com/technetwork/java/javase/8u20-relnotes-2257729.html the release notes] that installation to your installerversion-folderspecific directories does not indicate a static installation, silent installs add a new version instead of upgrading the old.
To uninstall the old Here, we present three different approaches to handle this, all with different advantages and drawbacks. You can use WMI to remove all versions of Java 7 before performing an upgrade (a popular solution), you can use PowerShell (or another scripting language) to identify and 8 remove all versions of Java other than the one you're deploying, or you can call <code>msiexec.exe</code> to explicitly remove known previous versions of Java. For the latter method, this page contains an example which removes the last version that WPKG deployed. You can also take a more thorough (but uglier to maintain) approach by trying to remove every known version of Java 8. For an example of how this works, see [Remove Java] or the oldest (pre-patch-in-place) JRE 6 packages on this page. People switching from one method to another should note also that two of these example packages put the Java MSIs in different locations. One package requires that you rename the 64-bit MSI so that you can keep it in the same directory as the 32-bit MSI, while the other keeps the MSIs in separate directories so that you can just copy files straight across without renaming them. All full examples install a 32-bit JRE on 32-bit Windows and install both 32- and 64-bit JREs on 64-bit Windows. In most cases the 32-bit JRE is sufficient for web use , but some programs running on the local computer (e.g. software for scientific computing or image editing) may require a 64-bit JRE. ==Removal with WMIC== These fragments can be used to alter the XML in [[##Install 32- and 64-bit JRE, remove the previous version|the next example]] to use <code>wmic product</code> to remove all other versions of Java before installing the new update. This method is simple and does not have any dependencies on other software for any supported version of Windows. The drawback to this method is that an intrinsic defect in the Win32_Product WMI class (see [https://support.microsoft.com/en-us/kb/974524 KB974524] and [http://wpkgblogs.orgtechnet.com/indexb/jchalfant/archive/2014/05/13/uninstalling-all-previous-versions-of-java-runtime-environment-using-application-supersedence-in-configuration-manager.php?title=Remove_Java aspx this TechNet blog post about the JRE]) causes Windows to perform a removal repair installation of every installed package]on the system when you run this query. This is extremely slow and can break software, including some versions of Java, that doesn't correctly implement it.
I suggest using Use this to remove all versions of Java 7:
<install cmd='wmic product where "name like &apos;Java 7%%&apos;" call uninstall' />
and to remove all Java 8 is similar:
Indeed you can use the last line to remove Java 8, like this:
<remove cmd='wmic product where "name like &apos;Java 8%%&apos;" call uninstall' />
It´s It's easier to mantain maintain even if it slower to run.
Java 6 can also be removed this way, but it has that ugly TM, so the command line must include it:
<install cmd='wmic product where "name like &apos;Java(tm) 6 %%&apos;" call uninstall' />
(You may need to put a space before (tm) for some versions)
 
These commands use pattern matching, so there is a risk of removing other unrelated packages that have e.g. "Java 8" in their names.
 
==Install 32- and 64-bit JRE, remove the previous version==
 
This package explicitly removes the previous version. This is the simplest and fastest method, but if a computer misses an update (e.g. if you push two versions of Java between runs of WPKG), this will miss removing an older JRE.
 
Get the offline-installers from http://www.oracle.com/technetwork/java/javase/downloads/index.html.
 
Extract the MSI-files:
*Run the installer on a test-computer
*Copy the MSI-file from C:\Users\username\AppData\LocalLow\Sun\Java to your installer-folder.
 
To uninstall the old Java 7 and 8 versions you can use a [http://wpkg.org/index.php?title=Remove_Java a removal package].
<source lang="xml">
</package>
</source>
 
==Install 32- and 64-bit JRE, remove all other versions using PowerShell==
 
This method uses a PowerShell script to look at uninstall information in the registry to find and remove all versions of Java 8 other than the one we're installing. This script handles downgrades correctly.
 
Because it requires PowerShell, this package may not work on versions of Windows prior to Windows 7 RTM. To use this package on Vista, Server 2008 or Server 2003, you'll need to install [[Microsoft Windows Management Framework|WMF]] 2.0.
 
This script uses pattern matching, so there is a risk of removing other unrelated packages that have e.g. "Java 8" in their names. This script could malfunction unless fixed when JRE 8u100 or JRE 80 are released.
 
This package contains an optional hack to fix installation problems sometimes seen with Java 7: It can use [[7-Zip]] to unpack <code>core.zip</code> if the installer didn't. I have not yet seen this problem with Java 8, so it's possible that this is an unnecessary precaution. If you want to use this, uncomment the first half of Step 4 and ensure that [[7-Zip]] is available at your site.
 
====Instructions & package====
 
# Get the offline installers from http://www.oracle.com/technetwork/java/javase/downloads/index.html.
# While logged on as an administrator, run the installers. When you get to the "Welcome to Java" dialog, click Cancel. '''Do not continue with the installation.'''
# Navigate to <code>%APPDATA%\..\LocalLow\Sun\Java</code>.
# You'll see temporary folders left by the Java installer. For JRE 8u45, they will be named <code>jre1.8.0_45</code> and <code>jre1.8.0_45_x64</code>. Move them to <code>%SOFTWARE%\Java\</code>.
# Update <code>%shortupdatever%</code> in this package.
 
<source lang="xml">
<?xml version="1.0" encoding="UTF-8"?>
<packages:packages
xmlns:packages="http://www.wpkg.org/packages" xmlns:wpkg="http://www.wpkg.org/wpkg" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.wpkg.org/packages ../xsd/packages.xsd" >
<package
id="jre8"
name="Java Runtime Environment 8"
revision="%version%"
reboot="false"
priority="20">
 
<!-- UPDATE INSTRUCTIONS:
 
1: Download the latest 32- and 64-bit offline installers.
2: While logged on as an administrator, run the installers. When you get
to the "Welcome to Java" dialog, click Cancel.
3: Navigate to %APPDATA%\..\LocalLow\Sun\Java
4: Grab the folders (e.g. jre1.8.0_45 and jre1.8.0_45_x64) that the Java
installer left there and move them to %SOFTWARE%\java\
5: Update %shortupdatever% in this package.
-->
 
<!-- <variable name="updatever" value="08" /> -->
<variable name="shortupdatever" value="45" />
<variable name="version" value="8.0.%shortupdatever%" />
 
<!-- Require WMF 2 if on an operating system that didn't come with PowerShell -->
<depends package-id="wmf2" os=".+6\.0\.\d{4}" /> <!-- Vista / Server 2008 -->
<depends package-id="wmf2" os=".+5\.[1-2]\.\d{4}" /> <!-- XP / Server 2003 -->
 
<check type="logical" condition="or">
<check type="uninstall" condition="exists" path="Java 8" />
<!-- <check type="uninstall" condition="exists" path="Java 8 Update %updatever%" /> -->
<check type="uninstall" condition="exists" path="Java 8 Update %shortupdatever%" />
<check type="uninstall" condition="exists" path="{26A24AE4-039D-4CA4-87B4-2F832180%shortupdatever%F0}" />
</check>
<check architecture="x64" type="logical" condition="or">
<check type="uninstall" condition="exists" path="Java 8 (64-bit)" />
<!-- <check type="uninstall" condition="exists" path="Java 8 Update %updatever% (64-bit)" /> -->
<check type="uninstall" condition="exists" path="Java 8 Update %shortupdatever% (64-bit)" />
<check type="uninstall" condition="exists" path="{26A24AE4-039D-4CA4-87B4-2F864180%shortupdatever%F0}" />
</check>
 
<!-- STEP 1: Kill process that may interfere with upgrade -->
<!-- <install cmd='taskkill /f /im jqs.exe /im iexplore.exe /im firefox.exe'> -->
<install cmd='taskkill /f /im jqs.exe'>
<exit code='any' />
</install>
 
 
<!-- STEP 2: Remove previous versions of Java 8 -->
<!-- Note that we can't just use UninstallString because Oracle decided
to use /i in it for 8u31. -->
<!-- Base64-encoded thing avoids quote nightmares and was made with
[Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes({
foreach ($i in get-itemproperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
where-object {$_.displayname -like "Java 8*" } |
where-object {$_.displayname -notlike "Java 8 Update $env:shortupdatever*"} ) {
msiexec /x $i.PSChildName.ToString() /qn | write-output
}}))
-->
<install cmd="powershell -noprofile -EncodedCommand DQAKAGYAbwByAGUAYQBjAGgAIAAoACQAaQAgAGkAbgAgAGcAZQB0AC0AaQB0AGUAbQBwAHIAbwBwAGUAcgB0AHkAIABIAEsATABNADoAXABTAG8AZgB0AHcAYQByAGUAXABNAGkAYwByAG8AcwBvAGYAdABcAFcAaQBuAGQAbwB3AHMAXABDAHUAcgByAGUAbgB0AFYAZQByAHMAaQBvAG4AXABVAG4AaQBuAHMAdABhAGwAbABcACoAIAB8AA0ACgAgACAAIAB3AGgAZQByAGUALQBvAGIAagBlAGMAdAAgAHsAJABfAC4AZABpAHMAcABsAGEAeQBuAGEAbQBlACAALQBsAGkAawBlACAAIgBKAGEAdgBhACAAOAAqACIAIAB9ACAAfAANAAoAIAAgACAAdwBoAGUAcgBlAC0AbwBiAGoAZQBjAHQAIAB7ACQAXwAuAGQAaQBzAHAAbABhAHkAbgBhAG0AZQAgAC0AbgBvAHQAbABpAGsAZQAgACIASgBhAHYAYQAgADgAIABVAHAAZABhAHQAZQAgACQAZQBuAHYAOgBzAGgAbwByAHQAdQBwAGQAYQB0AGUAdgBlAHIAKgAiAH0AIAApACAAewANAAoAIAAgAG0AcwBpAGUAeABlAGMAIAAvAHgAIAAkAGkALgBQAFMAQwBoAGkAbABkAE4AYQBtAGUALgBUAG8AUwB0AHIAaQBuAGcAKAApACAALwBxAG4AIAB8ACAAdwByAGkAdABlAC0AbwB1AHQAcAB1AHQADQAKAH0A" >
<exit code="any" />
</install>
<!-- Base64-encoded thing avoids quote nightmares and was made with:
[Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes({
foreach ($i in get-itemproperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
where-object {$_.displayname -like "Java 8*" } |
where-object {$_.displayname -notlike "Java 8 Update $env:shortupdatever*"} ) {
msiexec /x $i.PSChildName.ToString() /qn | write-output
}}))
-->
<install cmd="powershell -noprofile -EncodedCommand DQAKAGYAbwByAGUAYQBjAGgAIAAoACQAaQAgAGkAbgAgAGcAZQB0AC0AaQB0AGUAbQBwAHIAbwBwAGUAcgB0AHkAIABIAEsATABNADoAXABTAG8AZgB0AHcAYQByAGUAXABXAG8AdwA2ADQAMwAyAE4AbwBkAGUAXABNAGkAYwByAG8AcwBvAGYAdABcAFcAaQBuAGQAbwB3AHMAXABDAHUAcgByAGUAbgB0AFYAZQByAHMAaQBvAG4AXABVAG4AaQBuAHMAdABhAGwAbABcACoAIAB8AA0ACgAgACAAIAB3AGgAZQByAGUALQBvAGIAagBlAGMAdAAgAHsAJABfAC4AZABpAHMAcABsAGEAeQBuAGEAbQBlACAALQBsAGkAawBlACAAIgBKAGEAdgBhACAAOAAqACIAIAB9ACAAfAANAAoAIAAgACAAdwBoAGUAcgBlAC0AbwBiAGoAZQBjAHQAIAB7ACQAXwAuAGQAaQBzAHAAbABhAHkAbgBhAG0AZQAgAC0AbgBvAHQAbABpAGsAZQAgACIASgBhAHYAYQAgADgAIABVAHAAZABhAHQAZQAgACQAZQBuAHYAOgBzAGgAbwByAHQAdQBwAGQAYQB0AGUAdgBlAHIAKgAiAH0AIAApACAAewANAAoAIAAgAG0AcwBpAGUAeABlAGMAIAAvAHgAIAAkAGkALgBQAFMAQwBoAGkAbABkAE4AYQBtAGUALgBUAG8AUwB0AHIAaQBuAGcAKAApACAALwBxAG4AIAB8ACAAdwByAGkAdABlAC0AbwB1AHQAcAB1AHQADQAKAH0A" architecture="x64" >
<exit code="any" />
</install>
<!-- STEP 3: install -->
<install cmd='msiexec /i %SOFTWARE%\java\jre1.8.0_%shortupdatever%\jre1.8.0_%shortupdatever%.msi JU=0 JAVAUPDATE=0 AUTOUPDATECHECK=0 RebootYesNo=No WEB_JAVA=1 /q' />
<install architecture="x64" cmd='msiexec /i %SOFTWARE%\java\jre1.8.0_%shortupdatever%_x64\jre1.8.0_%shortupdatever%.msi JU=0 JAVAUPDATE=0 AUTOUPDATECHECK=0 RebootYesNo=No WEB_JAVA=1 /q' />
 
<!-- STEP 4: Fix broken installations
On the assumption that the Java 6 & Java 7 bug that leaves a broken
installation is not fixed, I'm including this workaround.
 
With Java 7's upgrade-in-place capability, I did this before the
upgrade, but since Oracle in their infinite wisdom decided to remove
that with Java 8, we do it now in case something went wrong.
-->
<!-- avoid interactive services detection if the old installation is broken -->
<!--
<depends package-id="7zip" />
<install cmd='%COMSPEC% /C if exist "%PROGRAMFILES(x86)%\Java\jre1.8.0_%shortupdatever%\core.zip" if not exist "%PROGRAMFILES(x86)%\Java\jre1.8.0_%shortupdatever%\bin\installer.dll" "%PROGRAMFILES%"\7-Zip\7z.exe" x -y -o"%PROGRAMFILES(x86)%\Java\jre1.8.0_%shortupdatever%" "%PROGRAMFILES(x86)%\Java\jre1.8.0_%shortupdatever%\core.zip"'>
<exit code="any" />
</install>
<install cmd='%COMSPEC% /C if exist "%PROGRAMFILES%\Java\jre1.8.0_%shortupdatever%\core.zip" if not exist "%PROGRAMFILES%\Java\jre1.8.0_%shortupdatever%\bin\installer.dll" "%PROGRAMFILES%"\7-Zip\7z.exe" x -y -o"%PROGRAMFILES%\Java\jre1.8.0_%shortupdatever%" "%PROGRAMFILES%\Java\jre1.8.0_%shortupdatever%\core.zip"'>
<exit code="any" />
</install>
-->
 
<!-- STEP 4.1
The Java installer has been reorganized and this probably no longer applies. It's left
here as a template, but feel free to remove it if you think you should.
-->
<!-- ... and because that won't avoid Interactive Service Detection if
there's no core.zip: -->
<!--
<install cmd='%COMSPEC% /C if exist "%PROGRAMFILES(x86)%" if exist "%PROGRAMFILES%\Java\jre1.8.0_%shortupdatever%\bin\msvcr100.dll" if not exist "%PROGRAMFILES%\Java\jre1.8.0_%shortupdatever%\bin\installer.dll" copy /y "%SOFTWARE%\java\jre8-installer-64.dll" "%PROGRAMFILES%\Java\jre1.8.0_%shortupdatever%\bin\installer.dll"'>
<exit code="any" />
</install>
<install cmd='%COMSPEC% /C if exist "%PROGRAMFILES(x86)%" if exist "%PROGRAMFILES(x86)%\Java\jre1.8.0_%shortupdatever%\bin\msvcr100.dll" if not exist "%PROGRAMFILES(x86)%\Java\jre1.8.0_%shortupdatever%\bin\installer.dll" copy /y "%SOFTWARE%\java\jre8-installer-32.dll" "%PROGRAMFILES(x86)%\Java\jre1.8.0_%shortupdatever%\bin\installer.dll"'>
<exit code="any" />
</install>
<install cmd='%COMSPEC% /C if not exist "%PROGRAMFILES(x86)%" if exist "%PROGRAMFILES%\Java\jre1.8.0_%shortupdatever%\bin\msvcr100.dll" if not exist "%PROGRAMFILES%\Java\jre1.8.0_%shortupdatever%\bin\installer.dll" copy /y "%SOFTWARE%\java\jre8-installer-32.dll" "%PROGRAMFILES%\Java\jre1.8.0_%shortupdatever%\bin\installer.dll"'>
<exit code="any" />
</install>
-->
 
 
 
<!-- STEP 5: cleanup -->
<!-- All architectures: remove Java Quick Starter -->
<install cmd='%COMSPEC% /C if exist "%PROGRAMFILES%\Java\jre1.8.0_%shortupdatever%\bin\jqs.exe" "%PROGRAMFILES%\Java\jre1.8.0_%shortupdatever\bin\jqs.exe" -unregister'>
<exit code='any' />
</install>
<install cmd='%COMSPEC% /C if exist "%PROGRAMFILES(x86)%\Java\jre1.8.0_%shortupdatever%\bin\jqs.exe" "%PROGRAMFILES(x86)%\Java\jre1.8.0_%shortupdatever\bin\jqs.exe" -unregister'>
<exit code='any' />
</install>
<!-- All architectures: disable Java Auto Update -->
<install cmd='REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v SunJavaUpdateSched /f'>
<exit code='any' />
</install>
 
<remove cmd='msiexec.exe /qn /x {26A24AE4-039D-4CA4-87B4-2F832180%shortupdatever%F0}' />
<remove architecture="x64" cmd='msiexec /qn /x {26A24AE4-039D-4CA4-87B4-2F864180%shortupdatever%F0}' />
 
<downgrade include="install" />
<upgrade include="install" />
</package>
</packages:packages>
</source>
 
====Details of the PowerShell script====
The PowerShell code is passed base64-encoded to avoid a quoting nightmare in the XML file. You can verify that it's correct (and re-encode it if you need to change it) with the following:
 
<source lang="powershell">
# 32-bit on 32-bit Windows, 64-bit on 64-bit Windows
[Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes({
foreach ($i in get-itemproperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
where-object {$_.displayname -like "Java 8*" } |
where-object {$_.displayname -notlike "Java 8 Update $env:shortupdatever*"} ) {
msiexec /x $i.PSChildName.ToString() /qn | write-output
}}))
 
# 32-bit on 64-bit Windows
[Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes({
foreach ($i in get-itemproperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
where-object {$_.displayname -like "Java 8*" } |
where-object {$_.displayname -notlike "Java 8 Update $env:shortupdatever*"} ) {
msiexec /x $i.PSChildName.ToString() /qn | write-output
}}))
</source>
 
Note that this consults the registry to discover what's installed instead of asking WMI; see [http://blogs.technet.com/b/heyscriptingguy/archive/2013/11/15/use-powershell-to-find-installed-software.aspx this article] to understand why.
 
The script uses the registry key to get the ClassID of installed JRE 8 instances instead of appending <code>/qn</code> to the uninstall string. The reason we do this is that for JRE 8u31, Oracle included <code>/i</code> in the UninstallString.
 
Output from <code>msiexec</code> is piped to <code>write-output</code> so that PowerShell will wait for msiexec to complete.
=Java Runtime Environment (JRE) 7=
91
edits

Navigation menu