Java Netbeans (macOS) install and JDK 8+ reporting

Description

The Java Netbeans IDE is a tool that is used to develop Java desktop, mobile, and web applications, as well as HTML5 applications with HTML, JavaScript, and CSS. The IDE is free and open source and has a large community of users and developers around the world.

Ingredients

  • FW Admin
  • Java JDK (prerequisite)

Directions

  1. Since Netbeans requires the Java Development Kit to be installed as a prerequisite, we need to determine if that is correctly installed first on the macOS client. We will create a new custom field (FW 12.7+) to collect this information. 

  2. In the "FileWave Admin console> Assistants> Edit Custom Fields...", define the following Client Script:

     #!/bin/bash
    
    # returns the JDK version.
    # 8 for 1.8.0_nn, 9 for 9-ea etc, and "no_java" for undetected
    jdk_version() {
    local result
    local java_cmd
    if [[ -n $(type -p java) ]]
    then
      java_cmd=java
    elif [[ (-n "$JAVA_HOME") && (-x "$JAVA_HOME/bin/java") ]]
    then
      java_cmd="$JAVA_HOME/bin/java"
    fi
    local IFS=$'\n'
    # remove \r for Cygwin
    local lines=$("$java_cmd" -Xms32M -Xmx32M -version 2>&1 | tr '\r' '\n')
    if [[ -z $java_cmd ]]
      then
        result=no_java
      else
      for line in $lines; do
        if [[ (-z $result) && ($line = *"version \""*) ]]
        then
          local ver=$(echo $line | sed -e 's/.*version "\(.*\)"\(.*\)/\1/; 1q')
          # on macOS, sed doesn't support '?'
          if [[ $ver = "1."* ]]
          then
            result=$(echo $ver | sed -e 's/1\.\([0-9]*\)\(.*\)/\1/; 1q')
          else
            result=$(echo $ver | sed -e 's/\([0-9]*\)\(.*\)/\1/; 1q')
          fi
        fi
      done
    fi
    echo "$result"
    }
    
    v="$(jdk_version)"
    echo $v
  3. In the Custom Field definition, I can choose to assign the field to all devices, or specifically target only a subset of devices in my inventory. I want to know the JDK version on only my macOS population, so I will create a smart group based off of the OS type and assign the custom field to that smart group. In the Custom Fields dialog, this will look like the following:

  4. To assign the custom field "Java JDK Version" to the smart group, "macOS", select the smart group in the Clients view and choose "Edit Custom Field(s) Association(s)...". Enable the field association for the "Java JDK Version" custom field. 
  5. After the devices send their inventory, this custom field will be evaluated locally on the macOS device and report back to the server. Based on this data, you can build a smart group based off of an inventory query for use in deployment of the Netbeans Installer:



  6. The result shows one device has the required prerequisites (Java JDK = 9) already installed. This group will be used to create an association for the NetBeans installer.



  7. Let's create the Installer and make the Association to the production smart group:

Prior to assigning any new fileset to a group of production machines, it is recommended (as part of IT best practice), to make the association to a few test devices first. Please ensure that you complete this step before moving to production deployment.

    1. In the Filesets view, choose "New Desktop Fileset"> MSI/PKG
    2. Define the NetBeans installer .pkg, downloaded from Oracle.
    3. Right click on the smart group "Deploy NetBeans IDE" and select "Create Association(s)..."
    4. Choose the fileset that you created in Step 2 and click "Create Association".
    5. Update Model.

Result

Only devices that meet the prerequisite of having the JDK installed will be targeted for the NetBeans IDE deployment. Sure, you can create a package that deploys both the JDK and the NetBeans IDE, but this way, you are creating a more streamlined workflow, saving download bandwidth by only deploying the necessary packages to your clients.