本文转自https://blog.csdn.net/lslk9898/article/details/73836745

近日有同事遇到在编译Maven项目时出现
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
的问题, 原以为这是个个例, 源于同事粗心, 配置环境出问题造成, 后到百度查看一下, 遇到这个问题的不在少数, 但是对问题的解释没有说到根源, 于是写下这篇博客供大家参阅, 如有纰漏, 还请指正.

错误代码节选:

  1. [ERROR] COMPILATION ERROR :
  2. [INFO] -------------------------------------------------------------
  3. [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
  4. [INFO] 1 error
  5. [INFO] -------------------------------------------------------------
  6. [INFO] ------------------------------------------------------------------------
  7. [INFO] BUILD FAILURE
  8. [INFO] ------------------------------------------------------------------------
  9. [INFO] Total time: 1.436 s
  10. [INFO] Finished at: 2017-06-28T11:16:07+08:00
  11. [INFO] Final Memory: 10M/151M
  12. [INFO] ------------------------------------------------------------------------
  13. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project manage: Compilation failure
  14. [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
  15. [ERROR] -> [Help 1]

但是编写普通Java Project编译运行却是正常的,下图为只有输出语句的普通java类

从上图中可以看出, java编译环境未jre1.7.0_17, 也就是说并没有配置成jdk目录, 然后看Eclipse-->Window-->preferences-->Java-->Installed JREs

为了演示出效果, 在测试之前, 我已经将系统java环境配置成如上图所示路径, 并只保留该配置, 由下图可以看出, 该路径是我所安装的两个JDK版本中的一个JDK自带的jre运行环境. 使用该环境编译普通项目没有问题, 但为什么会在编译Maven项目时出错呢?

我们看看Maven的环境是如何配置的:先找到Eclipse-->Window-->preferences-->Maven-->Installations

在Maven配置中, 我并没有使用Eclipse自带的Maven插件, 而是重新配置的Maven环境, 然后再看Eclipse-->Window-->preferences-->Maven-->User Settings

Maven设置使用的是Maven中conf文件夹下的settings.xml, 点击"open file" 在Eclipse中查看具体配置信息, 仅摘录与本错误信息相关的部分

  1. <profiles>
  2. <!-- profile
  3. | Specifies a set of introductions to the build process, to be activated using one or more of the
  4. | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
  5. | or the command line, profiles have to have an ID that is unique.
  6. |
  7. | An encouraged best practice for profile identification is to use a consistent naming convention
  8. | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
  9. | This will make it more intuitive to understand what the set of introduced profiles is attempting
  10. | to accomplish, particularly when you only have a list of profile id's for debug.
  11. |
  12. | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.-->
  13. <profile>
  14. <id>jdk-1.7</id>
  15. <activation>
  16. <activeByDefault>true</activeByDefault>
  17. <jdk>1.7</jdk>
  18. </activation>
  19. <properties>
  20. <maven.compiler.source>1.7</maven.compiler.source>
  21. <maven.compiler.target>1.7</maven.compiler.target>
  22. <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
  23. </properties>
  24. </profile>
  25. </profiles>

中间具体信息的理解, 可以参见 冰河winner 的博客. 也就是说, 根据上面的配置, 我们需要指定一个符合配置的JDK环境, 这是我们之前在Eclipse-->Window-->preferences-->Java-->Installed JREs下的配置就不行了, 而需要指定一个JDK目录, 例如我的JDK安装目录下的jdk1.7.0_17, 这也是这个错误出现的罪魁祸首. 不过对于Java开发者来说, Installed JREs中使用jdk目录而不适用jre目录也是最好的选择.

步骤:

然后再编译运行项目即可.

关于Maven项目build时出现No compiler is provided in this environment的处理(转)的更多相关文章

  1. 关于Maven项目build时出现No compiler is provided in this environment的处理

    版权声明:本文为博主原创文章,未经博主允许不得转载. http://blog.csdn.net/lslk9898/article/details/73836745 近日有同事遇到在编译Maven项目时 ...

  2. 【转载】关于Maven项目build时出现No compiler is provided in this environment的处理

    参考地址;https://blog.csdn.net/lslk9898/article/details/73836745

  3. 关于Maven项目install时出现No compiler is provided in this environment的处理

    关于Maven项目build时出现No compiler is provided in this environment的处理 新配置的Eclipse环境,运行现有项目没问题,一日,从svn上检出了一 ...

  4. maven打包时出现no compiler is provided in this environment

    我是使用maven打jar包时出现的问题,与我问题不同的可以查看下面链接是否有棒状 http://blog.csdn.net/lslk9898/article/details/73836745 可以确 ...

  5. 【maven】maven的web项目打包报错:No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK

    打包过程中报错如下: No compiler is provided in this environment. Perhaps you are running on a JRE rather than ...

  6. maven项目bulid失败_No compiler is provided in this environment.

    错误信息如下: [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather ...

  7. Maven构建项目出现No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? 你应该 ...

  8. Maven 项目 启动时 解决3 字节的 UTF-8 序列的字节 3 无效

    "org.activiti.bpmn.exceptions.XMLException: 3 字节的 UTF-8 序列的字节 3 无效." Maven 项目启动时,由于读XML配置文 ...

  9. Maven No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? 问题

    maven编译项目时出错,提示信息如下: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3 ...

随机推荐

  1. 线上SQL优化

    最近在线上发现很多性能有问题的sql,开发写sql语句的时候,没充分考虑是否用上索引了,所以这个坑得DBA来填,好了,废话不多说,把一些线上的优化经验跟大家分享. 由于是线上的表,所以就不公开具体的表 ...

  2. 【论文阅读】ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices

    ShuffleNet: An Extremely Efficient Convolutional Neural Network for MobileDevices

  3. linux(CentOS) 下mysql自动备份

    1.创建并编辑文件 /usr/sbin/bakmysql.sh,命令: vi /usr/sbin/bakmysql.sh 内容如下: db_user="root" db_passw ...

  4. Mybatis输入映射和输出映射

    本节内容: 输入参数映射 输出映射 resultMap Mapper.xml映射文件中定义了操作数据库的sql,每个sql是一个statement,映射文件是mybatis的核心. 一.环境准备 复制 ...

  5. hdu 5441 (2015长春网络赛E题 带权并查集 )

    n个结点,m条边,权值是 从u到v所花的时间 ,每次询问会给一个时间,权值比 询问值小的边就可以走 从u到v 和从v到u算不同的两次 输出有多少种不同的走法(大概是这个意思吧)先把边的权值 从小到大排 ...

  6. [更新]一份包含: 采用RSA JWT(Json Web Token, RSA加密)的OAUTH2.0,HTTP BASIC,本地数据库验证,Windows域验证,单点登录的Spring Security配置文件

    没有任何注释,表怪我(¬_¬) 更新: 2016.05.29: 将AuthorizationServer和ResourceServer分开配置 2016.05.29: Token获取采用Http Ba ...

  7. net mvc webapi 实用

    asp.net mvc webapi 实用的接口加密方法   在很多项目中,因为webapi是对外开放的,这个时候,我们就要得考虑接口交换数据的安全性. 安全机制也比较多,如andriod与webap ...

  8. Windows下调用caffe的matlab接口

    一.编译caffe的matlab接口 在我的这篇博客windows-caffe配置已经说了怎么编译了,这里就略过了. 编译成功后,会得到如下图所示文件: matlab接口就在matcaffe文件夹里. ...

  9. 022.Zabbix自定义(邮箱)脚本告警01

    待补充 有需要,请留言!

  10. 009.Zabbix幻灯片展示

    一 Slide shows简介 Slide shows在多个Screens之间以幻灯片的方式来展示,使一个屏幕可以显示多个页面. 二 Slide shows配置 2.1 创建多个Screen Slid ...