# 任务 ':compileJava' 执行失败 > 找不到 tools.jar。请检查 /usr/lib/jvm/java-11-openjdk-amd64 是否包含有效的 JDK 安装。

- **ID:** `java/gradle-task-execution-failure`
- **领域:** java
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Java 主目录路径指向 JRE 而非 JDK，或 JDK 安装不完整。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 8+ | active | — | — |

## 解决方案

1. **Set JAVA_HOME to a proper JDK installation** (95% 成功率)
   ```
   export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 (ensure it points to JDK, not JRE)
   ```
2. **Install a full JDK if missing** (90% 成功率)
   ```
   sudo apt-get install openjdk-11-jdk
   ```

## 无效尝试

- **Setting JAVA_HOME to a JRE directory** — JRE does not contain tools.jar, which is needed for annotation processing or certain plugins. (95% 失败率)
- **Downloading tools.jar separately and placing it in the JRE lib folder** — This is not a supported configuration and may cause compatibility issues. (90% 失败率)
