Java Licensing

  • 20 May 2019
  • Sean Huggans


With Oracle's move to licensed Java installations for business use, many organizations are still left wondering "we need Java, what do we do?". A viable solution for many organizations will be to move onto the open source OpenJDK as a standard, and only keep/deploy licensed Java if and when necessary. Oracle's java are built from OpenJDK in the first place, so this is a highly compatible and viable option for any organization using Java today (See reference below).

The following script will check for 32 and 64-bit versions of Oracle Java, remove them, and install OpenJDK in its place. For machines you know need to remain on Oracle Java, you can deploy a block file as seen in the script so that the deployment will "Skip it over" if it runs. This block file should also be defined in an OR statement in your detection method in the application package, as well as the Skipped.log file generated out if Oracle java is not detected by the script at all.

Download the script, as well as the latest version of both the 32-bit and 64-bit OpenJDK JREs and place them into your source directory. The script should auto-detect and use them regardless of minor version (Keep the naming scheme as downloaded). Use the OpenJDK binaries in your detection method, as well as the presence of the install.log in C:\ProgramData\JavaMig.

As an additional pro to moving to OpenJDK for those utilizing Patch My PC for third party patching, Patch My PC now patches OpenJDK as well!

Good luck!
- Sean

Code: 
#####################################################################################
# Oracle Java SE to OpenJDK Migration Script
# Script Author: Sean Huggans
# Script Date: 19.05.20.05
#####################################################################################
# Script will detect Oracle Java SE on clients, remove it, and install OpenJDK JRE
# This script will skip clients with the file defined in the $MigrationBlockPath
# variable present
#####################################################################################
# Variables
###########################
[string]$MigWorkingPath = "C:\ProgramData\JavaMig"
[string]$OracleJava32Path = "c:\Program Files (x86)\Java"
[string]$OracleJava64Path = "c:\Program Files\Java"
[string]$MigrationBlockPath = "C:\ProgramData\JavaMig\KeepOracleJava.block"
[boolean]$32BitJREPresent = $false
[boolean]$64BitJREPresent = $false
[string]$LogFile = "install.log"
[string]$LogDir = $MigWorkingPath
[string]$LogPath = "$($LogDir)\$($LogFile)"
 
###########################
# Functions
###########################
 
function Log-Action ($Message) {
	New-Item -ItemType directory -Path $LogDir -Confirm:$false -Force | out-null
	"[ $(get-date -Format 'yyyy.MM.dd HH:mm:ss') ] $($Message)" | Out-File $LogPath -Append
}
 
function Migrate-32BitJRE {
    Log-Action "Uninstalling 32-Bit Oracle Java SE JRE..."
    Start-Process -FilePath MSIExec -ArgumentList "/x $($(Get-ItemProperty "hklm:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | where-object {$_.DisplayName -like "Java 8 Update*"}).PSChildName) /qn" -Wait -WindowStyle Hidden
    Log-Action "Installing 32-Bit OpenJDK JRE..."
    $OpenJDKJRE32InstallerName = $(Get-ChildItem -Path $PSScriptRoot | Where-Object {$_.Name -like "OpenJDK8U-jre_x86-32*"}).Name
    Start-Process -FilePath MSIExec -ArgumentList "/i ""$($PSScriptRoot)\$($OpenJDKJRE32InstallerName)"" /qn /l*v ""$($LogDir)\OpenJDK32-MSIOutput.log""" -Wait -WindowStyle Hidden
    Log-Action "Installer finished running, see msi log for further details!"
}
 
function Migrate-64BitJRE {
    Log-Action "Uninstalling 64-Bit Oracle Java SE JRE..."
    Start-Process -FilePath MSIExec -ArgumentList "/x $($(Get-ItemProperty "hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | where-object {$_.DisplayName -like "Java 8 Update*"}).PSChildName) /qn" -Wait -WindowStyle Hidden
    Log-Action "Installing 64-Bit OpenJDK JRE..."
    $OpenJDKJRE64InstallerName = $(Get-ChildItem -Path $PSScriptRoot | Where-Object {$_.Name -like "OpenJDK8U-jre_x64*"}).Name
    Start-Process -FilePath MSIExec -ArgumentList "/i ""$($PSScriptRoot)\$($OpenJDKJRE64InstallerName)"" /qn /l*v ""$($LogDir)\OpenJDK64-MSIOutput.log""" -Wait -WindowStyle Hidden
    Log-Action "Installer finished running, see msi log for further details!"
}
 
###########################
# Script Logic
###########################
 
Log-Action "------------- Started Migration Script ------"
if (!(Test-Path $MigrationBlockPath)) {
    Log-Action "Migration Block File is NOT present, this workstation WILL be switched to OpenJDK!"
    if (Test-Path $OracleJava32Path) {
        if ($(Get-ChildItem -Path $OracleJava32Path -Recurse).Name -contains "java.exe") {
            Log-Action "32-Bit Oracle Java is Present on this workstation and will be replaced with 32-Bit OpenJDK!"
            $32BitJREPresent = $true
        }
    }
    if (Test-Path $OracleJava64Path) {
        if ($(Get-ChildItem -Path $OracleJava64Path -Recurse).Name -contains "java.exe") {
            Log-Action "64-Bit Oracle Java is Present on this workstation and will be replaced with 64-Bit OpenJDK!"
            $64BitJREPresent = $true
        }
    }
    if ($32BitJREPresent -eq $true) {
        Migrate-32BitJRE
    }
    if ($64BitJREPresent -eq $true) {
        Migrate-64BitJRE
    }
    if (($32BitJREPresent-eq $false) -and ($32BitJREPresent -eq $false)) {
        "Oracle Java is Not Present.  Skipping migration to OpenJDK" | Out-File -FilePath "$($LogDir)\Skipped.log" -Force
    }
} else {
    Log-Action "Notice!  Migration Block File is present, this workstation will not be switched to OpenJDK!"
}
Log-Action "------------- Ended Migration Script --------"

Vendor Links

Error | visuaFUSION Systems Solutions Blog

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /mnt/home/visuafus/public_html/bahusa.net/includes/common.inc:2861) in drupal_send_headers() (line 1551 of /mnt/home/visuafus/public_html/bahusa.net/includes/bootstrap.inc).
  • Error: Call to undefined function mail() in DefaultMailSystem->mail() (line 79 of /mnt/home/visuafus/public_html/bahusa.net/modules/system/system.mail.inc).

Error

The website encountered an unexpected error. Please try again later.