Overview
Managing Java versions on macOS endpoints can be challenging. The following scripts assist in removing older versions (specifically Oracle Java 8) and identifying installed versions for inventory purposes.
Script: Java_8_removal.sh
This script removes Oracle Java 8 (JDK 1.8) from the system and then updates the Jamf Pro inventory.
#!/bin/sh
# Java_8_removal.sh
#
#
# Created by Shri Sivakumaran C on 04/09/23.
#
LoggedUser=$(stat -f "%Su" /dev/console)
echo $LoggedUser
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -rf /User/$LoggedUser/Library/Application\ Support/Oracle/Java
rm -fr /Library/Java/JavaVirtualMachines/jdk1.8*
##update inventory to Jamf Pro
jamf recon
exit 0
Note: This script uses sudo to remove system-level files and directories.