博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于Maven项目build时出现No compiler is provided in this environment的处理
阅读量:2395 次
发布时间:2019-05-10

本文共 2876 字,大约阅读时间需要 9 分钟。

转载自:

错误代码节选:

[java]   
  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]   
  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.     
  14.   <profile>  
  15.     <id>jdk-1.7</id>  
  16.     <activation>  
  17.         <activeByDefault>true</activeByDefault>  
  18.         <jdk>1.7</jdk>  
  19.     </activation>  
  20.     <properties>  
  21.     <maven.compiler.source>1.7</maven.compiler.source>  
  22.     <maven.compiler.target>1.7</maven.compiler.target>  
  23.     <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>  
  24. </properties>  
  25.   </profile>  
  26. </profiles>  

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

步骤:

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

你可能感兴趣的文章
Spring中注解的使用
查看>>
Spring的认识
查看>>
maven项目出现如下错误,求指点;CoreException: Could not calculate build plan:
查看>>
理解Paxos算法的证明过程
查看>>
详解 JVM Garbage First(G1) 垃圾收集器
查看>>
Java 8 函数式编程入门之Lambda
查看>>
用高阶函数轻松实现Java对象的深度遍历
查看>>
WindowsApi+Easyx图形库的透明时钟
查看>>
Eclipse LUNA配置TomCat(非j2ee版本)
查看>>
树莓派安装mysql-srver报错 404 not found!
查看>>
Ubuntu 14.04LTS 下安装.net框架
查看>>
Eclipse 配置Groovy语言环境 && Java工程运行Groovy
查看>>
人工智能术语表
查看>>
Tensorflow Python API 翻译(sparse_ops)
查看>>
Tensorflow Python API 翻译(math_ops)(第一部分)
查看>>
Tensorflow Python API 翻译(math_ops)(第二部分)
查看>>
利用 TensorFlow 入门 Word2Vec
查看>>
使用数据驱动进行配对交易:简单交易策略
查看>>
课程---程序员炒股,如何计算股票投资组合的风险和收益
查看>>
人工智能资料库:第3辑(20170107)
查看>>