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

本文转自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?
的问题, 原以为这是个个例, 源于同事粗心, 配置环境出问题造成, 后到百度查看一下, 遇到这个问题的不在少数, 但是对问题的解释没有说到根源, 于是写下这篇博客供大家参阅, 如有纰漏, 还请指正.

错误代码节选:

[java] view plain copy

  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中查看具体配置信息, 仅摘录与本错误信息相关的部分

[html] view plain copy

  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目录也是最好的选择.

步骤:

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

原文地址:https://www.cnblogs.com/panxuejun/p/9203127.html

时间: 2024-08-27 18:57:13

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

[转]在Eclipse整合Maven3.6.3插件导入maven项目并编译时,控制台提示No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

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

maven 项目提交时不提交.project target等一些文件

1.首先在myeclipse10中安装maven的插件,将插件放入D:\Program Files (x86)\myEclipse10\MyEclipse Blue Edition 10\dropins\maven中, 2. 新建文件:maven.link填入如下内容:path=D:/Program Files (x86)/myEclipse10/MyEclipse Blue Edition 10/dropins/maven 3.重启myeclipse插件安装成功. 4.在myeclipse10

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 解决方案:  1- MyEclipse菜单 - Window - Preferences- Java - Installed JREs 将配置的JRE定位到JDK,最好是修改为jdk1.7 现在仍在探索,为什么我现在使用的MyEclipse( 版本2015 CI )里面的Maven JDK下拉选

No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? idea maven 打包报错问题解决

mvn clean install -X -Dmaven.test.skip=true -P dev 打包报错:No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? idea,项目,maven 也设置了统一的jdk,还是报错, 解决方法1:在maven的setting.xml 文件 <profiles> 标签中加入指定JDK的版本, <profile

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: Compilation failure [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? 在Eclipse的菜单中,进入 Windo

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

控制台输出的错误信息如下: [INFO] Scanning for projects... [INFO] [INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1 [INFO] [INFO] ----------------------------------------------------

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

使用Maven中的maven-build来本地调试项目,启动后在console出现如下错误信息 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile)on project XXXX: Compilation failure [ERROR] No compiler is provided in this environment. Perha

No compiler is provided in this environment. Perhaps you are running on a JRE ra

No compiler is provided in this environment. Perhaps you are running on a JRE ra,有需要的朋友可以参考下. 控制台输出的错误信息如下: [INFO] Scanning for projects... [INFO] [INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuild

maven 项目打包时无法解析读取properties文件

在做项目时遇见一个问题,无法解析properties文件的 内容 异常为 Could not resolve placeholder ......... 在此之前均有做相关的 配置 但是从未出现过如上异常,困惑了很久,最后把 war包提取出来得知   properties文件未被加载进项目中,因此无法识别. 但这的原因是为什么呢   ,原来此项目采用的是maven配置,但是maven在打包时将丢失properties文件,原因maven执行compile是只会扫描*.class文件. 那么这种请