Finding Java and Identifying Vendors

Finding Java and Identifying Vendors

Overview


This is a quick post that was discussed at the January 2020 MacAdmin meeting in reference to Oracle Java licensing.

  • Finding Java on your Mac Systems
    One option to find Java usage on a macOS system is to use the “find” command. The find command in UNIX is a command-line utility for walking a file hierarchy. It can be used to find files and directories and perform subsequent operations on them. It supports searching by file, folder, name, creation date, modification date, owner, and permissions. By using the ‘-exec’ other UNIX commands can be executed on files or folders found.

    Generic Syntax

    find [where to start searching from] [expression determines what to find] [-options] [what to find]

    To scan your Mac client systems to discover Java and applications bundling Java (i.e. JRE, JDK, etc.) with the application.

    find / -name "java" -type f -exec ls -s {} \; -exec {} -version \; -exec echo "" \;
    
  • Example Applications that Bundle Java

    Adobe Animate CC 2018
    Adobe CC/Adobe Animate CC 2018/Adobe Animate CC 2018.app/Contents/jre/jre1.8.0_121.jre/Contents/Home/bin/java
    java version “1.8.0_121”
    Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

    Mathematica
    Mathematica.app/Contents/SystemFiles/Java/MacOSX-x86-64/bin/java
    java version “1.8.0_161”
    Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

    MATLAB_R2019aMATLAB_R2019a.app/sys/java/jre/maci64/jre/bin/java
    java version “1.8.0_181”
    Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)SPSS
    SPSS/jre/bin/java
    java version “1.8.0_51”
    Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
    Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

    Stata
    Stata/utilities/java/macosx-x64/jre1.8.0_31/bin/java
    java version “1.8.0_31”
    Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

 

  • Identifying Vendors of Installed Java
    You can find the Java vendor by using the following script posted by Rich Trouton or if you are using Jamf Pro you can create an extension attribute to actively find the Java vendor installed on your managed Mac client systems.

    #!/bin/bash
    
    jdk_installed=$(/usr/libexec/java_home 2>/dev/null)
    result=None
    
    if [[ -n "$jdk_installed" ]]; then
    
       # If an installed JDK is detected, check to see if it's from a known vendor.
    
       javaJDKVendor=$(defaults read "${jdk_installed%/*}/Info" CFBundleIdentifier | grep -Eo "adoptopenjdk|amazon|apple|azul|openjdk|oracle|sap" | head -1)
       
       if [[ "$javaJDKVendor" = "adoptopenjdk" ]]; then
            result="AdoptOpenJDK"
       elif [[ "$javaJDKVendor" = "amazon" ]]; then
            result="Amazon"
       elif [[ "$javaJDKVendor" = "apple" ]]; then
            result="Apple"
       elif [[ "$javaJDKVendor" = "azul" ]]; then
            result="Azul"
       elif [[ "$javaJDKVendor" = "openjdk" ]]; then
            result="OpenJDK"
       elif [[ "$javaJDKVendor" = "oracle" ]]; then
            result="Oracle"
       elif [[ "$javaJDKVendor" = "sap" ]]; then
            result="SAP"
       else
            result="Unknown"
       fi   
    fi
    
    echo "<result>$result</result>"
    
    exit 0

Note, I have given this information to our campus central group (UIT) about the applications that are bundling Java with their application, and they have reached out to our campus software licensing group (Office of Software Licensing) about contacting the software vendors about their licensing or plan on migrating to non-Oracle Java, etc. But, currently, I haven’t received any official feedback from these campus groups.

3 Comments
  • Shri Sivakumaran
    Posted at 04:18h, 23 February Reply

    above extension attributes not show if more than one version of Java is installed on the system, is there any way to capture complete Java in the Mac?

    • Richard Glaser
      Posted at 10:07h, 10 March Reply

      Hi Shri:

      You should be able to modify, the code to meet your needs to output multiple Java versions.

  • Richard Glaser
    Posted at 10:11h, 10 March Reply

    For example, you should be able to use:

    defaults read “${jdk_installed%/*}/Info” CFBundleVersion

    or

    defaults read “${jdk_installed%/*}/Info” CFBundleShortVersionString

    To get java version.

Leave a Reply