Home » Java » 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?

Posted by: admin November 2, 2017 Leave a comment

Questions:

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?
Answers:
  1. On your Eclipse IDE, go into Window > Preferences > Java > Installed JREs > and check your installed JREs. You should have an entry with a JDK there.
  2. Select the Execution Env as show below. Click OK
  3. Then Right-Click on your Project -> Maven -> Update Project

Additionally, you may have to change Maven JRE (see @jlars62 answer) which is as follows. Goto Run -> Run Configurations, selecting the Maven Build I was running (from the left panel). Then, I clicked the JRE tab and selected the option Workspace default JRE

enter image description here

Questions:
Answers:

For me, it is exactly what the maven of eclipse complains

enter image description here

So, I press Edit button and change path to the JDK Folder, then clean project and everything starts to work

Questions:
Answers:

For me, nothing worked until I made this change to my pom.xml:

<build>
...
    <plugins>
    ...
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <fork>true</fork>
                <executable>C:\Program Files\Java\jdk1.7.0_45\bin\javac.exe</executable>
            </configuration>
        </plugin>
    </plugins>
</build>

Other Notes

I could see that m2e was executing in a JRE, not the JDK. Nothing I did changed this, including adding this to the eclipse.ini:

-vm
C:\Program Files\Java\jdk1.7.0_45\bin\javaw.exe

In the end I never got m2e to execute in a JDK, but setting the Java compiler explicitly (as above) did the trick.

Questions:
Answers:
  1. Set JAVA_HOME to JDK root – required if you run command line or maven(google for this variable)
  2. In project properties in section Java Compiller select required JDK – if you run directly from eclipse
Questions:
Answers:

I was getting this error when trying to do a maven build from within eclipse.

For me, the answer was going to Run -> Run Configurations, selecting the Maven Build I was running (from the left panel). Then, I clicked the JRE tab and selected the option Workspace default JRE

Questions:
Answers:

In my case it was solved by doing this:

Go to your ‘Runtime Configuration’ and configure your JRE to an JDK.

Select the right JDK for your Runtime

Select default JRE

I copied answer just in case it is deleted for some reason, but the source is here

Questions:
Answers:

Go to windows -> Preferences -> Java -> Installed JREs

may be jre is already added
enter image description here

click on Add -> Standard VM -> Next -> Directory

and browse for the JDK
in my case path was C:\Program Files\Java\jdk1.8.0_111

then Click on finish.

you will see window like thisenter image description here

select JDK -> Apply -> Ok

And You are done.

Questions:
Answers:

An alternative if jaipster’s answer does not work is to go to:
Window > Preferences > Java > Installed JREs

Then to edit the jre so that it points to the jdk and not the jre (the jre home filed in the jre package editor)

That worked for me.

Questions:
Answers:

If you are running the Maven command from cmd, make sure you set the jdk path before running the command. In my case, I have created a .bat file containing the following:

set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_60
start cmd.exe /k "cd c:\aem_proj\sis\aau"

Questions:
Answers:

I tried all of the above, however, still getting the same error message.

In my case an actual JRE was incorrectly used as JRE System Library in the project-specific build path which was obviously overriding all those other settings discussed here.

If that is so in your case try the following:

  1. Open the project-specific libraries of the Java Build Path: Right-click “Project > Build Path > Configure Build Path…” and select “Libraries” tab.
  2. Select the “JRE System Library” entry and hit “Remove”.
  3. Hit “Add Library…”.
  4. A wizard pops up. Select “JRE System Library” and hit “Next >”.
  5. Now select the correct JDK (in my case “Workspace default JRE”, which I
    configured using a JDK).
  6. Close wizard by hitting “Finish”.
  7. Close “Properties” dialog by hitting “OK”.
Questions:
Answers:

There is another possible answer to this question, and I may be the only person foolish enough to have stumbled upon this, but I think it’s worth adding, since none of the other answers applied as I already had those settings correct.

When you install a JDK, the installer asks you where you want to install the files. By default, on Windows, this is something like C:\Program Files\Java\jdk1.8.0_74 (or whatever version you are installing).

It then asks you for a directory to install the JRE to, which by default is something like C:\Program Files\Java\jre1.8.0_74.

Note that one is jdk1.8.0_74 and the other is jre1.8.0_74

I was rushing things, and thinking the installer was asking me the same question twice, set both my JDK and JRE install locations to D:\devtools\jdk\jdk1.8.0_74, resulting in the installer overwriting the JDK with the JRE. This resulted in (among other things) a missing javac.exe in my JDK bin, and the same error the OP reported here in all my maven builds.

Questions:
Answers:

There are several options to specify.

Steps:
Right on project in project explorer
Go to Run-> Run Configuration -> Click Maven Build -> Click on your build config/or create a new config.
You will see the window as the given snapshot below, click on JRE tab there.

You see you have 3 options 1) Workspace Default JRE 2)Execution Environment 3)Alternate JRE
enter image description here
1) Workspace Default JRE is set from ‘Window’ menu on the top -> Preferences -> Java -> Installed JREs -Here you can add your jdk
enter image description here
2) Execution Environment jdk can be set in pom.xml as mentioned by @ksnortum

<build>
<plugins>
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
            <fork>true</fork>
            <executable>C:\Program Files\Java\jdk1.7.0_45\bin\javac.exe</executable>
        </configuration>
    </plugin>
</plugins>

3) Alternate JRE can be used to select a jdk from your directory

Questions:
Answers:

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

Questions:
Answers:

I got a solution.

The most common solution for this problem is to change jdk location as my Installed JREs instead of the JRE location but that did not solve my problem this one time.

So I did the below to solve the problem.
Expand the Installed JREs tab and you will find a Execution environments tab.

Click on your favourite execution environment. In my case it was JAVASE-1.8. There it shows 2 options. JDK and JRE. Select JDK there and the problem is solved.

enter image description here

Questions:
Answers:

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.

Questions:
Answers:

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

Questions:
Answers:

In addition to answer above, I could say that just try to run Maven from the terminal (outside of Eclipse). In this way, if it builds from outside but not in Eclipse, you can understand that the problem should be in Eclipse.

Questions:
Answers:

Try this.

<build>
...
    <plugins>
    ...
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <fork>true</fork>
                <executable> path to jdk \bin\javac.exe</executable>
            </configuration>
        </plugin>
    </plugins>
</build>

Questions:
Answers:

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.

Questions:
Answers:

Add new JRE definition (select path JDK), worked for me.

http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-add_new_jre.htm

Questions:
Answers:

Are you missing any maven build.

Apart from above JRE changes.I still faced similar issue.I was missing JUnit dependency after adding it is working fine.

Hope this will help.