繁体   English   中英

mvn clean package error: 此环境没有提供编译器。 也许您在 JRE 而不是 JDK 上运行?

[英]mvn clean package error: No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

mvn clean package 时出现以下错误。我正在命令行上编译它。

>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

所以我遇到了同样的问题,终于能够解决它。 问题是我的 ~/.mavenrc 文件指向了错误的 java 路径。我已经将我的 java_home 定义为JAVA_HOME= /usr/libexec/java_home -v 1.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定义为它选择此/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home而不是/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home的 java 路径/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home 在 mavenrc 中将路径更改为/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home (或者在您定义了 java 路径的情况下)修复了此问题

对于 Mac,更新 bash_profile 中的“Java SE 8”/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home”。

执行以下命令:

vi ~/.bash_profile

更新 JAVA_HOME

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home

. ~/.bash_profile

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

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

set JAVA_HOME="C:\Program Files\Java\jdk1.8.0_171"

因为你在 Windows 上,你也可以在标准环境变量面板中设置它。

您可以通过运行mvn -version来验证您的配置:

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: C:\tools\apache-maven-3.6.3\bin\..
Java version: 1.8.0_232, vendor: Amazon.com Inc., runtime: C:\tools\java\jdk1.8.0_232\jre
Default locale: fr_CA, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

最后,它对我有用。 我必须在我的 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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM