(转)Maven Eclipse Compiler Error “No compiler is provided in this environment. …”

解决Maven安装在Eclipse中出现的编译器未提供错误

I got the following compilation error while running the Maven install command from Eclipse:

“No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?”

Go into Window > Preferences > Java > Installed JREs > and check your installed JREs. You should have an entry with a JDK there.

2013-03-08 10_37_19-Preferences

Go into Window > Preferences > Java > Installed JREs > Execution Environments

Select JavaSE-1.6, click the jdk checkbox on the right. Then use “update project configuration” from the maven menu.

2013-03-08 10_55_36-Preferences

from:http://cduu.wordpress.com/2013/03/08/maven-eclipse-compiler-error-no-compiler-is-provided-in-this-environment/

### 问题分析 Maven编译时提示错误信息 `No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?`,通常表明当前环境使用的是 **Java Runtime Environment (JRE)**,而非 **Java Development Kit (JDK)**。`maven-compiler-plugin` 依赖于 JDK 提供的编译工具(如 `javac`),而 JRE 不包含这些工具,因此导致编译失败。 ### 解决方法 #### 1. 确认当前使用的是 JDK 而非 JRE 在命令行中执行以下命令以检查当前 Java 环境: ```bash java -version javac -version ``` - `javac` 是 JDK 提供的编译器。如果 `javac` 命令不存在,则说明当前安装的是 JRE 或者环境变量未正确配置。 #### 2. 设置 `JAVA_HOME` 环境变量指向 JDK 确保 `JAVA_HOME` 指向 JDK 的安装目录,而不是 JRE。 - **Windows 系统:** - 打开系统环境变量设置,添加或修改 `JAVA_HOME` 变量,值为 JDK 的安装路径,例如: ``` C:\Program Files\Java\jdk1.8.0_301 ``` - 在 `Path` 环境变量中添加 `%JAVA_HOME%\bin`。 - **Linux/macOS 系统:** - 编辑 `~/.bashrc` 或 `~/.zshrc` 文件,添加以下内容: ```bash export JAVA_HOME=/usr/lib/jvm/jdk-11-openjdk export PATH=$JAVA_HOME/bin:$PATH ``` - 执行 `source ~/.bashrc` 或 `source ~/.zshrc` 使配置生效。 #### 3. 配置 IDE 使用 JDK 如果在 EclipseIntelliJ IDEA 中运行 Maven 项目,需确保 IDE 使用的是 JDK: - **Eclipse:** - 打开 `Window > Preferences > Java > Installed JREs`。 - 点击 `Add`,选择 `Standard VM`,然后浏览到 JDK 安装目录。 - 勾选新添加的 JDK 条目,并确保其作为默认 JRE。 - **IntelliJ IDEA(Mac/Linux):** - 打开 `File > Project Structure > SDKs`。 - 添加新的 JDK,选择 JDK 的安装路径。 - 在 `Project Settings > Project` 中选择该 JDK 作为项目 SDK。 #### 4. 检查 Jenkins 配置(如适用) 如果使用 Jenkins 构建项目,需确保 Jenkins 运行在 JDK 环境下: - 在 Jenkins 的全局工具配置中添加 JDK。 - 在 Jenkins 的构建配置中指定使用该 JDK,或在系统环境变量中配置 `JAVA_HOME`。 #### 5. Maven 插件配置(可选) 在 `pom.xml` 中明确指定 `maven-compiler-plugin` 使用的 Java 版本: ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>11</source> <target>11</target> </configuration> </plugin> </plugins> </build> ``` ### 验证修复 执行以下命令以验证是否修复成功: ```bash mvn clean compile ``` 如果编译成功,说明问题已解决。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值