code: def find_jdk_home_dir():
      
      for name in JDK_HOME_VARS:
          jdk_home_dir = os.environ.get(name, None)
          if jdk_home_dir \
                  and os.path.exists(os.path.join(jdk_home_dir, 'include')) \
                  and os.path.exists(os.path.join(jdk_home_dir, 'lib')):
              return jdk_home_dir
      logger.debug('Checking Maven for JAVA_HOME...')
      try:
          output = subprocess.check_output(['mvn', '-v'])
          if isinstance(output, bytes) and not isinstance(output, str):
              #PY3 related
              output = output.decode('utf-8')
          for part in output.split('\n'):
              if part.startswith('Java home:'):
                  path = part.split(':')[1].strip()
                  if path.endswith('jre'):
                      return path[0:-3]
                  
      except Exception:
          # maven probably isn't installed or not on PATH
          logger.debug('Maven not found on PATH. No JAVA_HOME found.')
  
      return None
docs: Try to detect the JDK home directory from Maven, if available, or use
      dedicated environment variables.
      :return: pathname if found, else None