常见的Maven报错原因是什么及怎么解决

65次阅读
没有评论

共计 4638 个字符,预计需要花费 12 分钟才能阅读完成。

这篇文章主要介绍“常见的 Maven 报错原因是什么及怎么解决”的相关知识,丸趣 TV 小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“常见的 Maven 报错原因是什么及怎么解决”文章能帮助大家解决问题。

报错:No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

解决方法

问题是将 JRE 作为 JDK 使用了,解决办法是安装 JDK,并将 JDK 设置到 Installed JREs 中

图示

错误堆栈

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project hibernate: Compilation failure[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[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

Failed to transfer http://xx.xx. Error code 400, Repository version policy: RELEASE does not allow metadata in path: cn/blueboz/train/hibernate/0.0.1-SNAPSHOT/maven-metadata.xml – [Help 1]

问题原因

如果是 deploy 出现问题,那么可能是因为将部署路径写错,如本例子,错误在于将 SNAPSHOT 版本写成 RELEASE 版本

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project hibernate: Failed to retrieve remote metadata cn.blueboz.train:hibernate:0.0.1-SNAPSHOT/maven-metadata.xml: Could not transfer metadata cn.blueboz.train:hibernate:0.0.1-SNAPSHOT/maven-metadata.xml from/to blueboz-snapshots (http://bluebozpc:8081/repository/maven-releases): Failed to transfer http://bluebozpc:8081/repository/maven-releases/cn/blueboz/train/hibernate/0.0.1-SNAPSHOT/maven-metadata.xml. Error code 400, Repository version policy: RELEASE does not allow metadata in path: cn/blueboz/train/hibernate/0.0.1-SNAPSHOT/maven-metadata.xml -  [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/MojoExecutionException

#

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project hibernate: Failed to deploy artifacts: Could not transfer artifact cn.blueboz.train:hibernate:jar:0.0.1-20170319.142156-1 from/to blueboz-snapshots (http://bluebozpc:8081/repository/maven-snapshots): Access denied to http://bluebozpc:8081/repository/maven-snapshots/cn/blueboz/train/hibernate/0.0.1-SNAPSHOT/hibernate-0.0.1-20170319.142156-1.jar. Error code 401, Unauthorized -  [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/MojoExecutionException

新建项目卡顿问题

将 maven 的配置设置为 offline, 离线更新就可以了

Fail to transfer …错误

Failure to transfer 
 org.codehaus.plexus:plexus-archiver:jar:3.4
 was cached in the local repository, 
 resolution will not be reattempted until 
 the update interval of [Bsdn] has elapsed or updates are forced. 
 Original error: 
 org.codehaus.plexus:plexus-archiver:jar:3.4 
 Bsdn (http://nexus.bsdn.org/content/groups/public/): No response received after 60000

一般是因为 nexus 私服链接超时,建议直接换一个私服即可,在用户路径下的 setting 中,修改成 aliyun 的私服

  mirror 
  id Alibaba /id 
  mirrorOf central /mirrorOf 
  name AliyunMaven /name 
  url http://maven.aliyun.com/nexus/content/groups/public/ /url /mirror

实在不行的话,根据 GAV,定位到本地缓存目录,将

\M2_HOME.m2\repository\org\codehaus\plexus\plexus-archiver\3.4

目录下的资源删掉,重新 UpdateProject 即可

Update Project 的时候变成 J2SE1.4

这个问题,网上提供了两种方案先给出代码,如果尝试了之后发现可以的话,请按照这种方式解决。如果还是不行,请看我的第三种终极解决方案

1. 解决方法一

$HOME 目录下的.m2 目录下的 settings.xml 文件的 profiles 节点下添加如下信息。Jdk 版本

profile  
  id jdk1.8 /id  
  activation  
  activeByDefault true /activeByDefault  
  jdk 1.8 /jdk  
  /activation  
  properties  
  maven.compiler.source 1.8 /maven.compiler.source  
  maven.compiler.target 1.8 /maven.compiler.target  
  maven.compiler.compilerVersion 1.8 /maven.compiler.compilerVersion  
  /properties   /profile

2. 解决方法二

在 build- pluginManager 下添加,或修改 maven-compiler-plugin 的默认配置信息

plugin 
  artifactId maven-compiler-plugin /artifactId 
  version 3.7.0 /version 
  configuration 
  source 1.8 /source 
  target 1.8 /target 
  /configuration /plugin

3. 更新插件方法

必须前面两个方法都尝试了之后,还是无效的情况下。才可以。这时候,你必须考虑是不是你的 IDE 的问题了。笔者使用的是 EclipseKepler 版本,最高支持 Jdk7。

点击进入 EclipseMarketPlace,输入 Maven

JavaTm 8 support for m2e for Eclipse Kepler SR2,安装就可以了,建议还是翻墙安装快些

关于“常见的 Maven 报错原因是什么及怎么解决”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注丸趣 TV 行业资讯频道,丸趣 TV 小编每天都会为大家更新不同的知识点。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-18发表,共计4638字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)