Maven遇到的错误汇总

时间:2023-03-09 15:45:13
Maven遇到的错误汇总

使用工具是MyEclipse10:

1.创建Maven项目出错

1.项目名带有Maven Webapp

解决方案:

Maven遇到的错误汇总


2.缺少jar

could not resolve archetype :   Could not find metadata org.apache.maven.archetypes:maven-archetype-webapp/maven-metadata.xml in loc

    原因:缺少archetype插件,比如:本地库中缺少 maven-archetype-quickstart插件

Maven遇到的错误汇总

  解决方案:

    1.百度下载:maven-archetype-quickstart-1.1.jar,  放在maven安装目录lib下,例如:D:\apache-maven-3.3.9\lib

    2.cmd窗口执行命令(进入jar包所在路径下):

    mvn install:install-file -DgroupId=org.apache.maven.archetypes -DartifactId=maven-archetype-quickstart -Dversion=1.1 -Dpackaging=jar -Dfile=maven-archetype-quickstart-1.1.jar

 

 参考:http://www.th7.cn/Program/java/201502/386237.shtml


3.连不上*库

could not calculate build plan

  原因:http://repo1.maven.org/maven2这个*仓库地址已经被屏蔽了,不能访问,所以maven用到的插件和jar下载失败,且你的电脑上的本地仓库,并没有下载好maven的插件等

  解决方案:

    1.把‘另外电脑中‘的本地仓库.m2目录拷贝到你的电脑上,并在maven conf settings.xml里面设置<localRepository>为.m2目录。

    2.有私服(例如nexus),就在settings.xml里面配置nexus地址,从它上面下载。


4.新建的项目,pom文件上红X:

Failure to transfer org.apache.maven:maven-artifact:pom:2.0.6 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven:maven-artifact:pom:2.0.6 from/to central (http://repo.maven.apache.org/maven2): No connector available to access repository central (http://repo.maven.apache.org/maven2) of type default using the available factories pom.xml /hello line 1 Maven Configuration Problem

Maven遇到的错误汇总

解决:

1.

打开Window-->preferences-->myeclipse-->maven4myeclipse--->user settings把local repository里面的地址复制。

  1. 如果你的myeclipse没有的话,就找到:

    c:\users\{你的电脑账号}\.m2\repository (一般在这个文件夹里)。

    比如我的:c:\users\long\.m2\repository

  2. 找打repository文件及后,在里面搜索 maven*.lastupdated。把搜出来的文件都删了。

  3. 重启myeclipse,右键项目--->maven4myeclipse--->update project...

  4. 勾选Force Update of Snapshots/Releases,然后ok退出,如果还是错误,不要着急,先等一会就好了。

 如果还是报错的话,那就怪我学艺不精吧


5.构建模型错

错误:Faile while instaling Dynamic Web Module 2.5

Maven遇到的错误汇总


2.部署maven项目出错

1.jdk编译出错

Unsupported major.minor version 51.0

原因:编译源码的jdk 和 tomcat 使用的jdk版本不一样

解决:项目------>右键------>properties------>Java Compiler------>Compiler Compliance Level------>选择你使用的JDK版本

Maven遇到的错误汇总


3.运行maven install的时候报错  

错误提示:  -Dmaven.multiModuleProjectDirectory system propery is not set.

原因: maven和jdk的环境变量没有相互指向对方

解决方法:

1.设一个环境变量M2_HOME指向你的maven安装目录

  M2_HOME=D:\Apps\apache-maven-3.3.1

2.Eclipse的设置:

  在Window->Preference->Java->Installed JREs->Edit

在Default VM arguments中设置

-Dmaven.multiModuleProjectDirectory=$M2_HOME

Maven遇到的错误汇总


4.pom.xml中标签出错

1.插件版本问题

错误提示:maven-dependency-plugin (goals "copy-dependencies", "unpack") is not support

解决方案: 在plugins之前添加如下pluginManagement,二者前后顺序如下:

<build>

<pluginManagement>
<plugins>
<plugin>
...
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
...
</plugin>
</plugins>

<finalName>A</finalName>
</build>

  

5.Eclipse的错误:

1.将maven项目转换成Dynamic Web Project
遇到错误:
找不到“Further Configuration available”时,去掉Dynamic Web Module的勾选,apply-确定之后重新打开勾选Dynamic Web Module就出现了