{"record":{"id":"bf6328ad8d15e562","repo":"SeleniumHQ/selenium","slug":"can-t-find-java-executable-located-at-java-path","errorCode":null,"errorMessage":"Can't find java executable located at {java_path}","messagePattern":"Can't find java executable located at (.+?)","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/remote/server.py","lineNumber":156,"sourceCode":"\n    @property\n    def env(self):\n        return self._env\n\n    @env.setter\n    def env(self, env):\n        if env is not None and not isinstance(env, collections.abc.Mapping):\n            raise TypeError(\"env must be a mapping of environment variables\")\n        self._env = env\n\n    @property\n    def java_path(self):\n        return self._java_path\n\n    @java_path.setter\n    def java_path(self, java_path):\n        if java_path and not os.path.exists(java_path):\n            raise OSError(f\"Can't find java executable located at {java_path}\")\n        self._java_path = java_path\n\n    def _wait_for_server(self, timeout=10):\n        start = time.time()\n        while time.time() - start < timeout:\n            try:\n                urllib.request.urlopen(self.status_url)\n                return True\n            except urllib.error.URLError:\n                time.sleep(0.2)\n        return False\n\n    def download_if_needed(self, version=None):\n        \"\"\"Download the server if it doesn't already exist.\n\n        Latest version is downloaded unless specified.\n        \"\"\"\n        args = [\"--grid\"]","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/remote/server.py#L138-L174","documentation":"Raised by the `java_path` setter when a path is supplied but `os.path.exists` reports it as absent. The server runner needs a real JRE binary to launch `java -jar <selenium-server>`, so it fails fast rather than producing a confusing Popen error later. It is an OSError.","triggerScenarios":"Setting `server.java_path = '/usr/lib/jvm/bin/java'` to a path that does not exist (typo, wrong install prefix, pointing at the JDK directory instead of the binary, or a relative path that doesn't resolve from the cwd).","commonSituations":"Hardcoding a java path from another machine/CI image. Using a Docker host path while running inside a container with a different mount. Pointing at the JAVA_HOME folder rather than the bin/java file.","solutions":["Verify the path exists and points at the executable binary, not a directory.","Run `which java` / `readlink -f $(which java)` to get the absolute resolved path.","Omit java_path entirely so the runner falls back to shutil.which('java') from PATH."],"exampleFix":"# before\nserver.java_path = '/opt/java'  # a directory\n\n# after\nimport shutil\nserver.java_path = shutil.which('java')  # or an absolute binary path that exists","handlingStrategy":"validation","validationCode":"import os\nif java_path and not os.path.exists(java_path):\n    raise FileNotFoundError(f'java not found at {java_path}')\nserver.java_path = java_path","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve and store the absolute path at startup, not a hardcoded string.","In containers, install a JRE and rely on PATH instead of a fixed java_path."],"tags":["configuration","validation","environment","server-runner"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}