mvn清理包错误:此环境中没有提供编译器也许您运行的是jre而不是jdk?

3z6pesqy  于 2021-06-30  发布在  Java
关注(0)|答案(3)|浏览(336)

在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
0mkxixxg

0mkxixxg1#

最后,我终于成功了。我必须在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>
628mspwn

628mspwn2#

所以我也有同样的问题,最终得以解决。问题是我的~/.mavenrc文件指向错误的java路径 JAVA_HOME= /usr/libexec/java\u主页-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 Plug-Ins/JavaAppletPlugin.plugin/Contents/Home 而不是 /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home . 将路径更改为 /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home 在mavenrc中(或者在您定义java路径的情况下),修复了这个问题

tgabmvqs

tgabmvqs3#

虽然在pom.xml中设置jdk的绝对路径是可行的,但这不是一种可移植的设置java的方法。当您提交并推送pom.xml时,您的同事不会感激您。
对于maven,必须确保javahome指向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"

相关问题