{"record":{"id":"e4e680624299374e","repo":"apache/cordova-android","slug":"failed-to-run-javac-version-make-sure-that-you","errorCode":null,"errorMessage":"Failed to run \"javac -version\", make sure that you have a JDK version 8 installed.\nYou can get it from the following location:\nhttps://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html","messagePattern":"Failed to run \"javac -version\", make sure that you have a JDK version 8 installed\\.\nYou can get it from the following location:\nhttps://www\\.oracle\\.com/technetwork/java/javase/downloads/jdk8-downloads-2133151\\.html","errorType":"exception","errorClass":"CordovaError","httpStatus":null,"severity":"error","filePath":"lib/env/java.js","lineNumber":58,"sourceCode":"    getVersion: async () => {\n        await java._ensure(process.env);\n\n        // Java <= 8 writes version info to stderr, Java >= 9 to stdout\n        let javacOutput;\n        try {\n            javacOutput = (await execa('javac', ['-version'], { all: true })).all;\n        } catch (ex) {\n            events.emit('verbose', ex.shortMessage);\n\n            let msg =\n            'Failed to run \"javac -version\", make sure that you have a JDK version 8 installed.\\n' +\n            'You can get it from the following location:\\n' +\n            'https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html';\n            if (process.env.JAVA_HOME) {\n                msg += '\\n\\n';\n                msg += 'Your JAVA_HOME is invalid: ' + process.env.JAVA_HOME;\n            }\n            throw new CordovaError(msg);\n        }\n\n        // We have to filter the output, because javac prints _JAVA_OPTIONS\n        // before printing the version which causes semver.coerce to fail to get\n        // the correct version if those options contain any numbers.\n        const match = /javac\\s+([\\d.]+)/i.exec(javacOutput);\n        return semver.coerce(match && match[1]);\n    },\n\n    /**\n     * Ensures that Java is installed. Will throw exception if not.\n     * Will set JAVA_HOME and PATH environment variables.\n     *\n     * This function becomes a no-op if already ran previously.\n     */\n    _ensure: async (environment) => {\n        if (javaIsEnsured) {\n            return;","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/apache/cordova-android/blob/7c1e190064e349ffa4bbc6ac37b77cd773e4dbd3/lib/env/java.js#L40-L76","documentation":"java.getVersion runs `javac -version` via execa; if the process fails to spawn (typically ENOENT - no javac on PATH, i.e. no JDK or only a JRE) it emits the execa shortMessage on verbose and throws this CordovaError. When JAVA_HOME is set but its bin/javac is unusable, the message additionally appends 'Your JAVA_HOME is invalid: <value>'. Note the text recommends JDK 8 - this code targets an older cordova-android; newer releases require JDK 17.","triggerScenarios":"check_java / `cordova requirements android` / any build when `javac` is not resolvable: JDK not installed, only a JRE installed (java exists but javac does not), or JAVA_HOME pointing at a JRE/deleted directory.","commonSituations":"CI images shipping a JRE only; JAVA_HOME left stale after a JDK upgrade or OS cleanup; fresh machine with no Java; PATH ordering hiding the right JDK.","solutions":["Install a JDK matching your cordova-android version (8 for this codebase; cordova-android >= 13 needs JDK 17).","Set JAVA_HOME to the JDK root such that $JAVA_HOME/bin/javac exists, and put $JAVA_HOME/bin on PATH.","Open a new shell (or `hash -r`) after PATH changes so the old 'command not found' cache clears."],"exampleFix":"# before\nexport JAVA_HOME=/usr/lib/jvm/java-8-openjdk-jre    # JRE: no javac\n\n# after\nexport JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64  # JDK: bin/javac exists\nexport PATH=\"$JAVA_HOME/bin:$PATH\"","handlingStrategy":"validation","validationCode":"const javac = await execa('javac', ['-version'], { all: true }).catch(() => null);\nif (!javac) {\n  throw new Error('No usable javac on PATH - install a JDK and set JAVA_HOME so $JAVA_HOME/bin/javac exists');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await check_reqs.check_java();\n} catch (e) {\n  if (/Failed to run \"javac -version\"/.test(e.message)) {\n    // JDK missing/invalid: install JDK, fix JAVA_HOME, open a new shell, rerun `cordova requirements android`\n  }\n  throw e;\n}","preventionTips":["Install the full JDK (not a JRE) matching your cordova-android version (8 here; 17 for cordova-android >= 13).","Assert JAVA_HOME/bin/javac exists in your env setup script before any cordova command.","After upgrading or removing JDKs, update JAVA_HOME and open a fresh shell."],"tags":["java","jdk","javac","java-home","environment-variable"],"backgroundTag":"jdk-not-installed","analyzedSha":"7c1e190064e349ffa4bbc6ac37b77cd773e4dbd3","analyzedAt":"2026-08-22T04:57:58.868Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}