code: def open_jar(self, path, overwrite=False, compressed=True, jar_rules=None):
      
      jar = Jar(path)
      try:
        yield jar
      except jar.Error as e:
        raise TaskError('Failed to write to jar at {}: {}'.format(path, e))
  
      with jar._render_jar_tool_args(self.get_options()) as args:
        if args:  # Don't build an empty jar
          args.append('-update={}'.format(self._flag(not overwrite)))
          args.append('-compress={}'.format(self._flag(compressed)))
  
          jar_rules = jar_rules or JarRules.default()
          args.append('-default_action={}'.format(self._action_name(jar_rules.default_dup_action)))
  
          skip_patterns = []
          duplicate_actions = []
  
          for rule in jar_rules.rules:
            if isinstance(rule, Skip):
              skip_patterns.append(rule.apply_pattern)
            elif isinstance(rule, Duplicate):
              duplicate_actions.append('{}={}'.format(
                rule.apply_pattern.pattern, self._action_name(rule.action)))
            else:
              raise ValueError('Unrecognized rule: {}'.format(rule))
  
          if skip_patterns:
            args.append('-skip={}'.format(','.join(p.pattern for p in skip_patterns)))
  
          if duplicate_actions:
            args.append('-policies={}'.format(','.join(duplicate_actions)))
  
          args.append(path)
  
          if JarTool.global_instance().run(context=self.context, runjava=self.runjava, args=args):
            raise TaskError('jar-tool failed')
docs: Yields a Jar that will be written when the context exits.
  
      :API: public
  
      :param string path: the path to the jar file
      :param bool overwrite: overwrite the file at ``path`` if it exists; ``False`` by default; ie:
        update the pre-existing jar at ``path``
      :param bool compressed: entries added to the jar should be compressed; ``True`` by default
      :param jar_rules: an optional set of rules for handling jar exclusions and duplicates