mvn compile -> Error No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

Хочу запустить проект через командную строку

mvn compile

но получаю ошибку:

[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:  3.095 s
[INFO] Finished at: 2020-02-22T14:35:57+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project test: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

В проекте есть pom.xml

<project>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

Если запукаю через IDE все компилирется нормально из консоли работает команда mvn -v:

Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T18:06:16+03:00)
Maven home: C:\Maven\apache-maven-3.6.2\bin\..
Java version: 1.8.0_161, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jre1.8.0_161
Default locale: en_US, platform encoding: Cp1251
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Как решить проблема?


Ответы (2 шт):

Автор решения: Vladimir Afanasyev

Вам нужно указать в системе JAVA_HOME / JRE_HOME.

В зависимости от системы:

  1. Windows 7 – My Computer > Properties > Advanced
  2. Windows 8 – Control Panel > System > Advanced System Settings
  3. Windows 10 – в поисковике вбейте Environment Variables > Edit the system environment variables

введите сюда описание изображения

Или через cmd (в примере - JDK. С JRE - аналогично):

setx -m JAVA_HOME "C:\Progra~1\Java\jdk1.8.0_XX"
→ Ссылка
Автор решения: Pavel

помогло спасибо. обновил PATH JavaHome и перезагрузил комп. проблема возникла судя по всему при устоновке второй IDE

→ Ссылка