@classmethod<EOL><INDENT>def configure_gateway(<EOL>cls, launch_jvm: bool = True,<EOL>gateway: Union[GatewayParameters, Dict[str, Any]] = None,<EOL>callback_server: Union[CallbackServerParameters, Dict[str, Any]] = False,<EOL>javaopts: Iterable[str] = (), classpath: Iterable[str] = '<STR_LIT>'):<DEDENT>
assert check_argument_types()<EOL>classpath = classpath if isinstance(classpath, str) else os.pathsep.join(classpath)<EOL>javaopts = list(javaopts)<EOL>for match in package_re.finditer(classpath):<EOL><INDENT>pkgname = match.group(<NUM_LIT:1>)<EOL>module = import_module(pkgname)<EOL>module_dir = os.path.dirname(module.__file__)<EOL>classpath = classpath.replace(match.group(<NUM_LIT:0>), module_dir)<EOL><DEDENT>if gateway is None:<EOL><INDENT>gateway = {}<EOL><DEDENT>if isinstance(gateway, dict):<EOL><INDENT>gateway.setdefault('<STR_LIT>', True)<EOL>gateway.setdefault('<STR_LIT>', True)<EOL>gateway = GatewayParameters(**gateway)<EOL><DEDENT>if isinstance(callback_server, dict):<EOL><INDENT>callback_server = CallbackServerParameters(**callback_server)<EOL><DEDENT>elif callback_server is True:<EOL><INDENT>callback_server = CallbackServerParameters()<EOL><DEDENT>return launch_jvm, gateway, callback_server, classpath, javaopts<EOL>
Configure a Py4J gateway.

:param launch_jvm: ``True`` to spawn a Java Virtual Machine in a subprocess and connect to
    it, ``False`` to connect to an existing Py4J enabled JVM
:param gateway: either a :class:`~py4j.java_gateway.GatewayParameters` object or a
    dictionary of keyword arguments for it
:param callback_server: callback server parameters or a boolean indicating if a
    callback server is wanted
:param javaopts: options passed to Java itself
:param classpath: path or iterable of paths to pass to the JVM launcher as the class path