[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-c

本文记录了在SSM框架商城项目中遇到的Maven编译失败问题,具体表现为环境中未提供编译器,疑似使用JRE而非JDK。通过调整配置指明JDK路径后,成功解决了该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] e3-manager ......................................... SUCCESS [  1.000 s]
[INFO] e3-manager-pojo .................................... FAILURE [  0.595 s]
[INFO] e3-manager-dao ..................................... SKIPPED
[INFO] e3-manager-interface ............................... SKIPPED
[INFO] e3-manager-service ................................. SKIPPED
[INFO] e3-manager-web ..................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.928 s
[INFO] Finished at: 2017-08-10T17:27:02+08:00
[INFO] Final Memory: 15M/180M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project e3-manager-pojo: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :e3-manager-pojo

今天在写一个商城项目,SSM框架整合ok了,主要的模块也都搭建好了,但是在最后测试的时候出现了上面这个很有意思的错误,所以写下这篇博客。

在我执行Maven install的时候报了一个No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?,一看见这个报错就知道环境哪里没配置好,最开始以为是JDK的版本问题,我本地装的是JDK1.8,但是项目里都是设置的1.7.百度了一下后找到了下面这个让我很懵的设置。。。

对!就是把一个叫你Install JREs的地方直接换成JDK的路径,换了过后就ok了。疑问

### Maven 编译过程中 `maven-compiler-plugin` 插件版本 3.1/3.8.1 执行失败的原因分析 在 Maven 的构建流程中,如果遇到类似于 `Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile)` 或者更高版本(如 3.8.1)的错误提示,通常表明编译阶段出现了致命问题。以下是可能原因及其解决方案: #### 可能原因一:Java 版本不匹配 Maven 使用的 JDK 版本与项目所需的 Java 版本可能存在冲突。例如,在 pom.xml 文件中指定了 `<source>` 和 `<target>` 属性为特定的 Java 版本,而实际运行环境使用的却是不同的 JDK 版本。 **解决方案**: 确认项目的 JDK 配置是否一致。可以通过以下方式调整: ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> ``` 上述配置指定源码和目标字节码均为 Java 8[^4]。同时,确保本地安装的 JDK 版本也与此保持一致。 --- #### 可能原因二:Docker 容器内的 JDK 不兼容 当使用 Dockerfile 构建镜像时,容器内部的 JDK 版本可能导致类似的错误。例如,宿主机上使用的是较新的 JDK,但在容器内却启用了旧版 JDK。 **解决方案**: 更新 Dockerfile 中的基础镜像至支持所需 JDK 版本的官方镜像。例如: ```dockerfile FROM maven:3.8.1-jdk-11 AS build COPY src /usr/src/app/src COPY pom.xml /usr/src/app RUN mvn -f /usr/src/app/pom.xml clean package ``` 此示例选择了基于 OpenJDK 11 的 Maven 镜像[^3],从而避免因 JDK 版本差异引发的问题。 --- #### 可能原因三:插件版本过低或过高 某些情况下,`maven-compiler-plugin` 的版本可能无法适配当前的 MavenJDK 环境。例如,早期版本的插件可能不完全支持最新的 JDK 功能。 **解决方案**: 升级到更稳定的插件版本(如 3.8.1),并重新尝试构建过程: ```xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> </plugin> ``` --- #### 可能原因四:依赖项缺失或损坏 有时,由于网络连接不稳定或其他因素,可能会导致部分依赖未成功下载或者被破坏。 **解决方案**: 清理本地仓库缓存,并强制重新拉取所有依赖项: ```bash mvn clean install -U ``` 该命令会刷新已有的依赖文件,确保其完整性[^2]。 --- #### 总结代码片段 综合考虑以上情况,推荐如下完整的 pom.xml 配置作为参考: ```xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project> ``` --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值