Java mvn清理包错误:此环境中未提供编译器。也许您运行的是JRE而不是JDK?

Java mvn清理包错误:此环境中未提供编译器。也许您运行的是JRE而不是JDK?,java,maven,package,Java,Maven,Package,mvn清理包时出现以下错误。我正在命令行上编译此代码 >mvn -f myapp/pom.xml clean package 这是我的命令,下面是错误。有人能帮我吗 [INFO] Compiling 1 source file to C:\VaibhavNandkule\myapp\target\classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION

mvn清理包时出现以下错误。我正在命令行上编译此代码

>mvn -f myapp/pom.xml clean package
这是我的命令,下面是错误。有人能帮我吗

[INFO] Compiling 1 source file to C:\VaibhavNandkule\myapp\target\classes
[INFO] -------------------------------------------------------------
[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.170 s
[INFO] Finished at: 2020-01-24T19:20:14+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project myapp: 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中添加以下代码

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

最后,它对我起了作用。我必须在pom.xml中添加以下代码

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

虽然在pom.xml中设置JDK的绝对路径是可行的,但这不是设置java的可移植方式。当您提交并推送pom.xml时,您的同事不会感激您

对于Maven,您必须确保JAVA_HOME指向JDK的根

set JAVA_HOME="C:\Program Files\Java\jdk1.8.0_171"
由于您的应用程序是在Windows上进行的,因此您也可以在“标准环境变量”面板中进行设置

您可以通过运行mvn来验证配置-版本:


虽然在pom.xml中设置JDK的绝对路径是可行的,但这不是设置java的可移植方式。当您提交并推送pom.xml时,您的同事不会感激您

对于Maven,您必须确保JAVA_HOME指向JDK的根

set JAVA_HOME="C:\Program Files\Java\jdk1.8.0_171"
由于您的应用程序是在Windows上进行的,因此您也可以在“标准环境变量”面板中进行设置

您可以通过运行mvn来验证配置-版本:


所以我也遇到了同样的问题,最终解决了。问题是我的~/.mavenrc文件指向了错误的java路径。我已经将我的java_home定义为java_home=/usr/libexec/java_home-v1.8 键入命令:/usr/libexec/java_home-V。 它会显示出这样的东西

Matching Java Virtual Machines (2):
1.8.261.12 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_261 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
现在的问题是将/usr/libexec/java_home-V定义为java路径,它选择的是/Library/Internet plugins/JavaAppletPlugin.plugin/Contents/home,而不是/Library/java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/home。
在mavenrcor中将路径更改为/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home在您曾经定义过Java路径的情况下修复了这个问题,因此我也遇到了同样的问题,并且最终能够解决它。问题是我的~/.mavenrc文件指向了错误的java路径。我已经将我的java_home定义为java_home=/usr/libexec/java_home-v1.8 键入命令:/usr/libexec/java_home-V。 它会显示出这样的东西

Matching Java Virtual Machines (2):
1.8.261.12 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_261 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home
现在的问题是将/usr/libexec/java_home-V定义为java路径,它选择的是/Library/Internet plugins/JavaAppletPlugin.plugin/Contents/home,而不是/Library/java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/home。
在mavenrcor中将路径更改为/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home在您定义Java路径的情况下,修复了Mac的此问题,请在bash_概要文件中更新Java SE 8/Library/Java/JavaVirtualMachines/jdk1.8.0_261;.jdk/Contents/Home

执行以下命令:

vi~/.bash_简介

更新JAVA_主页

导出JAVA_HOME=/Library/JAVA/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/HOME


.~/。bash_概要文件

对于Mac,在bash_概要文件中更新JavaSE8/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home

执行以下命令:

vi~/.bash_简介

更新JAVA_主页

导出JAVA_HOME=/Library/JAVA/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/HOME


.~/。bash_profile

我强烈建议更改为项目目录,只使用mvn clean package,但这不会解决问题。请参阅Mathieu的答案。我强烈建议更改为项目目录,只使用mvn clean package,但这不会解决问题。请参阅Mathieu的答案。这很有意义,谢谢Mathieu。我一定要试试。太好了。别忘了把这个作为结束这个问题的答案。这很有意义,谢谢马修。我一定要试试。太好了。别忘了将此设置为结束此问题的答案。我在mac中遇到了相同的问题,将JAVA_HOME直接更改为/Library/JAVA/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/HOME也会起作用我在mac中遇到了相同的问题,将JAVA_HOME直接更改为/Library/JAVA/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/HOME也会起作用