Changes

Java

16,792 bytes removed, 10:01, 6 October 2011
Alternate Java 6 (JRE/SDK) Installer (seems very complicated): Removing this section as it's insanely over complicated and covers more than just JRE and SDK
</package>
</source>
 
=Alternate Java 6 (JRE/SDK) Installer (seems very complicated)=
This is my personal solution. Works properly for me starting from Java 6 Update 11.
It works on Windows XP and Vista. 64-bit OS is supported as well as 32-bit OS.
It also seems that Sun is not going to install each Java update into an independent directory. This will hopefully eliminate the need to uninstall previous versions manually.
 
===Download===
First of all download the offline installers. Do not download the new Online installers. It might work as well but I did not try it.
After download you should have the following files (or a subset of it):
* jdk-6u11-windows-i586-p.exe
* jdk-6u11-windows-x64.exe
* jre-6u11-windows-i586-p.exe
* jre-6u11-windows-x64.exe
 
If you just deploy JRE, then you do not need to download the JDK packages. Similarly you do not need the x64 packages if you deploy to 32-bit OS only.
 
===Prepare installation===
Unfortunately the .exe installers do not always work silently when the "/v/qn..." switch is used. On 64-bit OS it might yield a "package not found" error in silent installation. That's why I recommend to pre-extract the packages.
 
# Run the installer as usual (e.g. double-click "jdk-6u10-windows-i586-p.exe"
# Get the extracted installer from "%AppData%\Sun\Java\" ("%LocalAppData%\..\LocalLow\Sun\Java" in Vista) and copy them to the package deployment folder. Do this for all packages you like to deploy. Here's a sample how my directory structure looks after extracting and copying:
#* JavaSE/install.cmd
#* JavaSE/jdk1.6.0_11_32/jdk-6u11-windows-i586-p.exe
#* JavaSE/jdk1.6.0_11_32/jdk1.6.0_11.msi
#* JavaSE/jdk1.6.0_11_32/sb160110.cab
#* JavaSE/jdk1.6.0_11_32/sd160110.cab
#* JavaSE/jdk1.6.0_11_32/sj160110.cab
#* JavaSE/jdk1.6.0_11_32/sp160110.cab
#* JavaSE/jdk1.6.0_11_32/sr160110.cab
#* JavaSE/jdk1.6.0_11_32/ss160110.cab
#* JavaSE/jdk1.6.0_11_32/st160110.cab
#* JavaSE/jdk1.6.0_11_32/sz160110.cab
#* JavaSE/jdk1.6.0_11_x64/jdk-6u11-windows-x64.exe
#* JavaSE/jdk1.6.0_11_x64/jdk-6u11-windows-x64.msi
#** Note: This installer seems to be different from all the others. It uses a different package format and extracts to "%TEMP%\<UID>". So you have to grab the MSI file from there.
#* JavaSE/jre1.6.0_11_32/Data1.cab
#* JavaSE/jre1.6.0_11_32/jre-6u11-windows-i586-p.exe
#* JavaSE/jre1.6.0_11_32/jre1.6.0_11.msi
#* JavaSE/jre1.6.0_11_x64/Data1.cab
#* JavaSE/jre1.6.0_11_x64/jre-6u11-windows-x64.exe
#* JavaSE/jre1.6.0_11_x64/jre.msi
#** Note: I had to rename the msi file from "jre1.6.0_10.msi" to "jre.msi" in order to install properly. Without this fix it failed with a message that it could not locate "jre.msi". Seems to be a bug within the msi package.
#* JavaSE/unattended-jdk-uninstall.cmd
#* JavaSE/unattended-jdk.cmd
#* JavaSE/unattended-jre-uninstall.cmd
#* JavaSE/unattended-jre.cmd
 
Please NOTE: There are some *.cmd scripts listed which I use as install scripts. The scripts are listed within the following chapters.
 
===Package definition===
<source lang="xml">
<?xml version="1.0" encoding="utf-8" ?>
<packages>
 
<package id='JRE' name='Java runtime environment' revision='16010' priority='50' reboot='false' >
<!-- Java runtime environment -->
<check type='logical' condition='or'>
<check type='uninstall' condition='exists' path='Java(TM) 6 Update 11' />
<check type='uninstall' condition='exists' path='Java(TM) 6 Update 11 (64-bit)' />
</check>
<install cmd='"%SOFTWARE%\JavaSE\unattended-jre.cmd"' />
<remove cmd='"%SOFTWARE%\JavaSE\unattended-jre-uninstall.cmd"' />
<upgrade cmd='"%SOFTWARE%\JavaSE\unattended-jre.cmd"' />
</package>
 
</packages>
</source>
 
As you can see the package just runs the unattended* cmd script which will make sure the right packages for the currently running operating system is executed.
 
NOTE: This package definition is for JRE installation. If you would like to deploy JDK, then just refer to unattended-jdk* scripts insted.
 
===The scripts===
As listed above there are some scripts required. And here they come...
 
NOTE: The unattended* scripts are basically identical for all versions - they just need to list the correct MSI file within the header (PKG32 and PKG64 variables).
 
unattended-jre.cmd / unattended-jre-uninstall.cmd (both files are identical, you might also link them on Unix/Linux level).
<source lang="dos">
@echo off
 
REM Get MSI file by executing installation and then grab tje MSI file from
REM the %LocalAppData%\..\LocalLow\Sun\Java folder
 
set PKG32=jre1.6.0_11_32\jre1.6.0_11.msi
set PKG64=jre1.6.0_11_x64\jre.msi
set EXIT_CODE=0
 
set INSTALLER=install.cmd
 
echo Applying Java Runtime
 
REM Determine aciton
if "%~nx0" == "unattended-jre-uninstall.cmd" (
if not "%ProgramFiles(x86)%" == "" (
goto 64bituninstall
) else (
goto 32bituninstall
)
)
 
if not "%ProgramFiles(x86)%" == "" goto 64bitinstall
goto 32bitinstall
 
:64bitinstall
echo Installing 64bit edition
call "%~dp0%INSTALLER%" msiinstall "%PKG32%" "%PKG64%" "" "/qn /norestart IEXPLORER=1 NETSCAPE6=0 MOZILLA=1 REBOOT=Suppress JAVAUPDATE=0 WEBSTARTICON=0"
if %ERRORLEVEL% GTR %EXIT_CODE% set EXIT_CODE=%ERRORLEVEL%
REM Install 32-bit version as well - used by 32-bit applications
call "%~dp0%INSTALLER%" msiinstall "%PKG32%" "%PKG32%" "" "/qn /norestart IEXPLORER=1 NETSCAPE6=0 MOZILLA=1 REBOOT=Suppress JAVAUPDATE=0 WEBSTARTICON=0"
if %ERRORLEVEL% GTR %EXIT_CODE% set EXIT_CODE=%ERRORLEVEL%
goto end
 
:64bituninstall
echo Uninstalling 64bit edition
call "%~dp0%INSTALLER%" msiuninstall "%PKG32%" "%PKG64%"
if %ERRORLEVEL% GTR %EXIT_CODE% set EXIT_CODE=%ERRORLEVEL%
REM Uninstall 32-bit version as well - used by 32-bit applications
call "%~dp0%INSTALLER%" msiuninstall "%PKG32%" "%PKG32%"
if %ERRORLEVEL% GTR %EXIT_CODE% set EXIT_CODE=%ERRORLEVEL%
goto end
 
 
:32bitinstall
echo Installing 32bit edition
call "%~dp0%INSTALLER%" msiinstall "%PKG32%" "%PKG64%"
if %ERRORLEVEL% GTR %EXIT_CODE% set EXIT_CODE=%ERRORLEVEL%
goto end
 
:32bituninstall
echo Uninstalling 32bit edition
call "%~dp0%INSTALLER%" msiuninstall "%PKG32%" "%PKG64%"
if %ERRORLEVEL% GTR %EXIT_CODE% set EXIT_CODE=%ERRORLEVEL%
goto end
 
 
:end
exit /B %EXIT_CODE%
</source>
 
unattended-jdk.cmd / unattended-jdk-uninstall.cmd (both files are identical, you might also link them on Unix/Linux level).
<source lang="dos">
@echo off
 
REM Get MSI file by executing installation and then grab tje MSI file from
REM the %LocalAppData%\..\LocalLow\Sun\Java folder
 
set PKG32=jdk1.6.0_10_32\jdk1.6.0_11.msi
set PKG64=jdk1.6.0_10_x64\jdk-6u11-windows-x64.msi
set EXIT_CODE=0
 
set INSTALLER=install.cmd
 
echo Applying Java Runtime
 
REM Determine aciton
if "%~nx0" == "unattended-jdk-uninstall.cmd" (
if not "%ProgramFiles(x86)%" == "" (
goto 64bituninstall
) else (
goto 32bituninstall
)
)
 
if not "%ProgramFiles(x86)%" == "" goto 64bitinstall
goto 32bitinstall
 
:64bitinstall
echo Installing 64bit edition
call "%~dp0%INSTALLER%" msiinstall "%PKG32%" "%PKG64%" "" "/qn /norestart IEXPLORER=1 NETSCAPE6=0 MOZILLA=1 REBOOT=Suppress JAVAUPDATE=0 WEBSTARTICON=0"
if %ERRORLEVEL% GTR %EXIT_CODE% set EXIT_CODE=%ERRORLEVEL%
REM Install 32-bit version as well - used by 32-bit applications
call "%~dp0%INSTALLER%" msiinstall "%PKG32%" "%PKG32%" "" "/qn /norestart IEXPLORER=1 NETSCAPE6=0 MOZILLA=1 REBOOT=Suppress JAVAUPDATE=0 WEBSTARTICON=0"
if %ERRORLEVEL% GTR %EXIT_CODE% set EXIT_CODE=%ERRORLEVEL%
goto end
 
:64bituninstall
echo Uninstalling 64bit edition
call "%~dp0%INSTALLER%" msiuninstall "%PKG32%" "%PKG64%"
if %ERRORLEVEL% GTR %EXIT_CODE% set EXIT_CODE=%ERRORLEVEL%
REM Uninstall 32-bit version as well - used by 32-bit applications
call "%~dp0%INSTALLER%" msiuninstall "%PKG32%" "%PKG32%"
if %ERRORLEVEL% GTR %EXIT_CODE% set EXIT_CODE=%ERRORLEVEL%
goto end
 
 
:32bitinstall
echo Installing 32bit edition
call "%~dp0%INSTALLER%" msiinstall "%PKG32%" "%PKG64%" "" "/qn /norestart IEXPLORER=1 NETSCAPE6=0 MOZILLA=1 REBOOT=Suppress JAVAUPDATE=0 WEBSTARTICON=0"
if %ERRORLEVEL% GTR %EXIT_CODE% set EXIT_CODE=%ERRORLEVEL%
goto end
 
:32bituninstall
echo Uninstalling 32bit edition
call "%~dp0%INSTALLER%" msiuninstall "%PKG32%" "%PKG64%"
if %ERRORLEVEL% GTR %EXIT_CODE% set EXIT_CODE=%ERRORLEVEL%
goto end
 
 
:end
exit /B %EXIT_CODE%
</source>
 
As you can see the script is mainly used to determine the correct installer for 32- or 64-bit operating system.
 
NOTE: I am installing 32-bit version on 64-bit OS as well. This assures that 32-bit browsers can run the Java plug-in too.
 
Due to the fact that lots of installers are using always the same silent switches I prepared a generic "install.cmd" script. So I can just pass the installer filename and the type of installer as parameters and I do not have to care about the switches each time.
So here it comes:
 
<source lang="dos">
@echo off
 
REM Usage:
REM msiinstall.cmd <type> <32-bit-installer> <64-bit-installer> [installer-location [custom-options]]
REM where type is one of
REM msiinstall Install the given MSI package
REM msiuninstall Uninstall the given MSI package
REM innosetup Inno setup
REM installshield Install shield
REM nsis Nullsoft install system (NSIS)
REM custom Custom installer - options required in this case
REM 32-bit-installer Full file name (including extension) of 32-bit installer
REM 64-bit-installer Full file name (including extension) of 64-bit installer
REM installer-location Path where the installers are stored, if empty assumes directory where install.cmd is
REM custom-options Replace the default installer options with the ones given
 
REM Global variables
set INSTALL_CMD=
set EXIT_CODE=0
 
REM Get command type
set TYPE=%~1
 
REM Get 32-bit installer name
set CMD32=%~2
 
REM Get 64-bit installer name
set CMD64=%~3
 
REM get file path
set INSTALLER_PATH=%~dp0
if not "%~4" == "" (
set INSTALLER_PATH=%~4
)
 
set OPTIONS=
if not "%~5" == "" (
set OPTIONS=%~5
)
 
REM Detect which system is used
if not "%ProgramFiles(x86)%" == "" goto 64bit
goto 32bit
 
 
REM ##########################################################################
REM 64-bit system detected
REM ##########################################################################
:64bit
REM Determine 64-bit installer to be used
echo 64-bit system detected.
REM set INSTALLER64=
if not "%CMD64%" == "" (
set INSTALLER64=%CMD64%
) else (
REM Use 32-bit installer if available, no 64-bit installer available.
if not "%CMD32%" == "" (
echo Using 32-bit installer, no 64-bit installer specified.
set INSTALLER64=%CMD32%
) else (
echo Neither 64-bit nor 32-bit installer specified. Exiting.
goto usage
)
)
 
REM Check if installer is valid
if exist "%INSTALLER_PATH%%INSTALLER64%" (
set INSTALL_CMD=%INSTALLER_PATH%%INSTALLER64%
) else (
echo Installer "%INSTALLER_PATH%%INSTALLER64%" cannot be found! Exiting.
exit /B 97
)
goto installerselection
 
 
REM ##########################################################################
REM 32-bit system detected
REM ##########################################################################
:32bit
REM Determine 32-bit installer to be used
echo 32-bit system detected.
set INSTALLER32=
if not "%CMD32%" == "" (
set INSTALLER32=%CMD32%
) else (
echo No 32-bit installer specified. Exiting.
exit /B 96
)
 
 
REM Check if installer is valid
if exist "%INSTALLER_PATH%%INSTALLER32%" (
set INSTALL_CMD=%INSTALLER_PATH%%INSTALLER32%
) else (
echo Installer "%INSTALLER_PATH%%INSTALLER32%" cannot be found! Exiting.
exit /B 95
)
goto installerselection
 
 
 
REM ##########################################################################
REM select installer system
REM ##########################################################################
:installerselection
if /i "%TYPE%" == "msiinstall" goto msiinstaller
if /i "%TYPE%" == "msiuninstall" goto msiuninstaller
if /i "%TYPE%" == "innosetup" goto innoinstaller
if /i "%TYPE%" == "installshield" goto installshieldinstaller
if /i "%TYPE%" == "nsis" goto nsisinstaller
if /i "%TYPE%" == "custom" goto custominstaller
goto usage
 
 
 
:msiinstaller
echo Installing "%INSTALL_CMD%"
if "%OPTIONS%" == "" (
set OPTIONS=/qn /norestart
)
start /wait "Software installation" msiexec /i"%INSTALL_CMD%" %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto end
 
 
:msiuninstaller
echo Uninstalling "%INSTALL_CMD%"
if "%OPTIONS%" == "" (
set OPTIONS=/qn /norestart
)
start /wait "Software uninstallation" msiexec /x "%INSTALL_CMD%" %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto end
 
 
:innoinstaller
echo Installing "%INSTALL_CMD%"
REM if "%OPTIONS%" == "" (
REM set OPTIONS=/verysilent /norestart /sp-
REM )
start /wait "Software installation" "%INSTALL_CMD%" /verysilent /norestart /sp- %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto end
 
 
:installshieldinstaller
echo Installing "%INSTALL_CMD%"
start /wait "Software installation" "%INSTALL_CMD%" /s %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto end
 
 
:nsisinstaller
echo Installing "%INSTALL_CMD%"
start /wait "Software installation" "%INSTALL_CMD%" /S %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto end
 
:custominstaller
if "%OPTIONS%" == "" goto usage
echo Installing "%INSTALL_CMD%"
start /wait "Software installation" "%INSTALL_CMD%" %OPTIONS%
set EXIT_CODE=%ERRORLEEL%
goto end
 
:usage
echo Usage:
echo "%~nx0 <type> <32-bit-installer> <64-bit-installer> [installer-location [custom-options]]"
echo where type is one of
echo msiinstall Install the given MSI package
echo msiuninstall Uninstall the given MSI package
echo innosetup Inno setup
echo installshield Install shield
echo nsis Nullsoft install system (NSIS)
echo custom Custom installer - options required in this case
echo 32-bit-installer Full file name (including extension) of 32-bit installer
echo 64-bit-installer Full file name (including extension) of 64-bit installer
echo installer-location Path where the installers are stored
echo custom-options Replace the default installer options with the ones given
exit /B 99
 
:end
exit /B %EXIT_CODE%
</source>
 
That's it. This framework is quite easy to re-use for upgrades. The only thing you have to do is to download the Java Offline installers for the edition you like to deploy, then extract it, put the files to a sub-folder of the scripts (see directory structure outlined above) and then change the PKG32 and PKG64 paths on top of the scripts accordingly.
 
==Java Uninstall Method==
 
If you are just starting out with WPKG and want to be able to uninstall all versions of Java prior to your first package, you can use JavaRa (http://raproducts.org/javara.html) to silently uninstall all prior versions of the JRE.
 
There's also a scripting solution. It can also be used for other programs like Adobe Reader.
 
<source lang="dos">
@ECHO OFF
rem Find all programs installed on the computer
ECHO Finding all Java-installations...
FOR /f %%I IN ('REG QUERY HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall') DO ECHO %%I | FIND "{" > NUL && CALL :All-Installations %%I
ECHO Finished removing Java.
GOTO :EOF
 
:All-Installations
rem Filter out all but the Sun Installations
FOR /f "tokens=2*" %%T IN ('REG QUERY %1 /v Publisher 2^> NUL') DO ECHO Removing: %%U | FIND "Sun" > NUL && CALL :Sun-Installations %1
GOTO :EOF
:Sun-Installations
rem Filter out all but the Sun-Java Installations. Note the tilde + n, which drops all the subkeys from the path
FOR /f "tokens=2*" %%T IN ('REG QUERY %1 /v DisplayName 2^> NUL') DO ECHO Removing: %%U | FIND "Java" && CALL :Sun-Java-Installs %~n1
GOTO :EOF
:Sun-Java-Installs
rem Run uninstaller in unattended mode
START "" /WAIT "%WinDir%\SYSTEM32\msiexec.exe" /x%1 /qn
GOTO :EOF
</source>
 
Here's a JScript variant using the MSI ActiveX object. Execute it with cscript. Any JRE from 1.4.2 up to including 1.6u7 will be removed:
<source lang="javascript">
var msi = new ActiveXObject("WindowsInstaller.Installer");
msi.UILevel = 2; // INSTALLUILEVEL_NONE
var products = msi.Products;
for (var i = 0; i < products.Count; ++i)
if (products.Item(i).match(/^\{(?:7148F0A8-6813-11D6-A77B-00B0D0142|3248F0A8-6813-11D6-A77B-00B0D01[56])/))
msi.ConfigureProduct(products.Item(i), 0, 2 /* INSTALLSTATE_ABSENT */);
</source>
 
And here is a VBS equivalent
 
<source lang="javascript">
 
Set msi = CreateObject("WindowsInstaller.Installer")
Set re = new regexp
Const msiInstallStateAbsent = 2
 
re.pattern="{(" & _
"7148F0A8-6813-11D6-A77B-00B0D0142" & _
"|3248F0A8-6813-11D6-A77B-00B0D01[56]" & _
")}"
 
msi.UILevel = 2
 
For Each msipackage In msi.Products
info = msipackage & " = " & msi.ProductInfo(msipackage, "ProductName")
WScript.Echo(Info)
Next
 
For Each msipackage In msi.Products
if re.test(msipackage) Then
WScript.Echo("Uninstalling " +msipackage)
msi.ConfigureProduct msipackage, 0, msiInstallStateAbsent
End If
Next
</source>
 
=Another Java 6 SDK Installer =
577
edits