No compiler is provided in this environment. Perha

2020-01-22 12:09发布

I'm compiling a project in Eclipse using m2eclipse. I set the JDK path in Eclipse like this:

Windows-->preferences-->installed jres--> jdk1.7.xx  path

But this is showing an error

[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] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.424s
[INFO] Finished at: Tue Oct 29 15:21:01 IST 2013
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-   plugin:3.1:compile (default-compile) on project TEST-WEB: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

30条回答
戒情不戒烟
2楼-- · 2020-01-22 12:49

i faced the same issue, the mistake i made was i added jre path only in the path var,not jdk path .When jdk path was added to path and build the maven project its working perfect .Thanks all

查看更多
爷的心禁止访问
3楼-- · 2020-01-22 12:50

I faced the same issue while trying to build a jar file of my project application using mvn clean install, though the application was working fine while running from Eclipse.

The issue was, indeed too naive, that I had not set the JAVA_HOME environment variable. All I had to do is set JAVA_HOME environment variable to JDK directory, make sure it is not till "\bin" and without semi-colon ";".

enter image description here

How I understood it is as:

The application worked fine in Eclipse as JRE System Library was referring to JRE inside the JDK folder instead of external JRE folder without JDK. [As explained very well in other answers]

This configuration does not apply to maven command that we run on command prompt. It will still look for JAVA_HOME variable to access the JRE System library and when it is not found it refers to external JRE folder without JDK.

查看更多
够拽才男人
4楼-- · 2020-01-22 12:50

I did the following change and it worked for me.Hope it helps someone.enter image description here

查看更多
太酷不给撩
5楼-- · 2020-01-22 12:52

I tried most of the answers without success. What worked for me was (after following https://stackoverflow.com/a/21279068/2408893):

  • right click on project -> Properties
  • select Java Build Path
  • select the JRE System Library
  • click edit
  • In execution environment select a jdk

enter image description here

  • click Finish
  • build and run
查看更多
孤傲高冷的网名
6楼-- · 2020-01-22 12:53

I got same issue and i just add JAVA_HOME to environment variables.

env var

  • If you are using eclipse, just refer https://stackoverflow.com/a/21279068/6097074
  • If you are using intellij, just after adding JAVA_HOME open command prompt from project directory and run mvn clean install(don't use intellij terminal).
查看更多
我欲成王,谁敢阻挡
7楼-- · 2020-01-22 12:53

There are several answers regarding this question but all are related to right path configuration of JDK, but with JRE only we can solve this problem.

We just need to make use of deployment assembly to configure the path of packaged war file of the Java EE Project and then re-run the maven-install.

Steps to make use of deployment assembly:

  1. Right click on the Jave EE project --> click on Properties --> click on Deployment Assembly

  2. Click on Add button --> Click on Archives from the File System --> Click on next --> Click on Add --> Go to the .m2\respository directory and search for the war file generated --> Select war file --> Click on Open button --> Click on Apply --> OK

  3. Right click on the project --> Click on Maven Install under Run As

This will build your project successfully, without any compiler error.

Hope this solves the problem without JDK.

查看更多
登录 后发表回答