在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
3条答案
按热度按时间0mkxixxg1#
最后,我终于成功了。我必须在pom.xml中添加以下代码。
628mspwn2#
所以我也有同样的问题,最终得以解决。问题是我的~/.mavenrc文件指向错误的java路径
JAVA_HOME=
/usr/libexec/java\u主页-v1.8键入命令:
/usr/libexec/java_home -V
. 它会显示出这样的东西现在问题来了
/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路径的情况下),修复了这个问题tgabmvqs3#
虽然在pom.xml中设置jdk的绝对路径是可行的,但这不是一种可移植的设置java的方法。当您提交并推送pom.xml时,您的同事不会感激您。
对于maven,必须确保javahome指向jdk的根。
由于您的应用程序是在windows上运行的,所以您可以在标准环境变量面板中设置它。
您可以通过运行
mvn -version
: