Maven错误总结

来源:互联网 发布:小米看电视直播软件 编辑:程序博客网 时间:2024/06/03 20:51
错误1
导入maven后,项目报错,其中点开pom文件后,报错情况如图:
单击顶端的Overview后侧的红色提示,弹出如下详细信息。
仔细查看上图中的详细信息,发现错误原因是缺少了jar包“org.apache.commons:commons-lang3:jar:3.3.2”.
打开maven中设置的jar包路径文件夹,并找到缺少jar包的具体路径,删除该文件夹。
按住alt+F5,弹出如图对话框,点击确认,maven会自动从服务器重新下载最新的jar包。
下载完成后,程序可正常运行,pom文件不在报错。
错误1.1
[ERROR]   The project com.z[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Child module D:\Git\.git\Video\VideoMvn03\Video-dao of D:\Git\.git\Video\VideoMvn03\pom.xml does not exist @
[ERROR] Child module D:\Git\.git\Video\VideoMvn03\Video-pojo of D:\Git\.git\Video\VideoMvn03\pom.xml does not exist @
[ERROR] Child module D:\Git\.git\Video\VideoMvn03\Video-service of D:\Git\.git\Video\VideoMvn03\pom.xml does not exist @
[ERROR] Child module D:\Git\.git\Video\VideoMvn03\Video-tools of D:\Git\.git\Video\VideoMvn03\pom.xml does not exist @
[ERROR] Child module D:\Git\.git\Video\VideoMvn03\Video-web of D:\Git\.git\Video\VideoMvn03\pom.xml does not exist @
 @
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]  hiyou:VideoMvn03:0.0.1-SNAPSHOT (D:\Git\.git\Video\VideoMvn03\pom.xml) has 5 errors
[ERROR]     Child module D:\Git\.git\Video\VideoMvn03\Video-dao of D:\Git\.git\Video\VideoMvn03\pom.xml does not exist
[ERROR]     Child module D:\Git\.git\Video\VideoMvn03\Video-pojo of D:\Git\.git\Video\VideoMvn03\pom.xml does not exist
[ERROR]     Child module D:\Git\.git\Video\VideoMvn03\Video-service of D:\Git\.git\Video\VideoMvn03\pom.xml does not exist
[ERROR]     Child module D:\Git\.git\Video\VideoMvn03\Video-tools of D:\Git\.git\Video\VideoMvn03\pom.xml does not exist
[ERROR]     Child module D:\Git\.git\Video\VideoMvn03\Video-web of D:\Git\.git\Video\VideoMvn03\pom.xml does not exist
[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/ProjectBuildingException
maven项目编译的标准输出路径就是mavenProject/target/classes, 项目右键 build path--configure build path--java build path--source,把default output folder改成mavenProject/target/classes,在菜单栏project下把自动编译打勾。
错误1.2
就说明:src/main/java下面的mapper文件夹下的xml没有被加载
 <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
           
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
错误2.1
用Eclipse创建一个maven工程,网上有很多资料,这里不再啰嗦。
右键maven工程,进行更新
在弹出的对话框中勾选强制更新,如图所示
稍等片刻,pom.xml的红叉消失了。。。
错误2.2
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5
解决方法:
1、查看windows -> Preferences -> maven 的settings.xml文件中.m2的位置
2、然后将.m2/repository/org/apache/maven/plugins目录下的文件夹全部删除
3、选中maven项目,右键--》maven--》update让maven重新下载依赖包
错误2.3
在新建maven工程时报错:
Java代码  

    Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart:RELEASE from any of the configured repositories.   
    Could not resolve artifact Missing org.apache.maven.archetypes:maven-archetype-quickstart:pom:RELEASE

解决思路:在本地库中装载maven-archetype-quickstart
Java代码 
    1.从 http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/   
    下载最新版maven-archetype-quickstart-1.1.jar 
    2.cmd窗口执行命令:  
    mvn install:install-file -DgroupId=org.apache.maven.archetypes -DartifactId=maven-archetype-quickstart -Dversion=1.1 -Dpackaging=jar -Dfile=E:\jar\maven-archetype-quickstart-1.1.jar
再创建maven工程,成功!
同理,如果创建web项目报错,就下载maven-archetype-webapp-1.0.jar,执行如下命令:
Java代码  

    mvn install:install-file -DgroupId=org.apache.maven.archetypes -DartifactId=maven-archetype-webapp -Dversion=1.0 -Dpackaging=jar -Dfile=E:\jar\maven-archetype-webapp-1.0.jar

错误2.4

1.问题:创建maven项目时,选择的是创建web-app项目,但是结果配置之后,却没有web.xml文件。
2.解决办法:

重新创建一次,勾选web.xml或者重新创建一个web.xml文件。

最后点击ok,web.xml文件生成成功。
错误2.5
你跟新的jar包中,缺少这个包, 你重新加载一次
第一步:选中项目,先project----》clean一下。
第二步:选中项目,Debug AS------>maven clean
第三部:加载pom里的jar,Debug AS------>maven INSTALL
错误2.6

    pring-web 的jar包没导进去

    jar包邮冲突,把重复的jar包删除

    在web.xml加上<context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext-*.xml</param-value>
        </context-param>

因为默认的读取的是/WEB-INF下的配置文件,如果配置文件在src中要把路径改为类路径底下
4.把工程刷新一下,因为工程是部署在服务器底下的,要把加入的jar包部署到工程里。
错误2.7

问题:

使用Myeclips 2014创建Maven web项目后,

JSP 报错:The superclass "javax.servlet.http.HttpServlet" was not found

如下图所示:

针对上述问题有下列两种解决方案:

解决1:

1. 在Maven的pom文件中加入依赖即可:

    <dependency>  
        <groupId>javax.servlet</groupId>  
        <artifactId>javax.servlet-api</artifactId>  
        <version>3.1.0</version>  
    </dependency>  

解决2: 添加库

项目 --> 右键 --> Build Path --> Configure Build Path.. --> Add Library -->MyEclipse Server Library

因为项目中用到Tomcat 8,所以添加了Apache Tomcat v8.0 Runtime Libraries

如下图所示:

错误2.8

在使用Maven时,经常会遇到jar包冲突的问题,解决办法:

在pom.xml文件中使用maven的exclusions工具,语法如下:

避免Hadoop-client-2.2.0.jar引入hadoop-hdfs-2.2.0.jar

    <dependency>  
      <groupId>org.apache.hadoop</groupId>  
      <artifactId>hadoop-client</artifactId>  
      <version>2.2.0</version>  
      <exclusions>  
        <exclusion>  
            <groupId>org.apache.hadoop</groupId>  
            <artifactId>hadoop-hdfs</artifactId>  
        </exclusion>  
      </exclusions>  
    </dependency>  

加入后,hadoop-client-2.2.0.jar将不会引入hadoop-hdfs-2.2.0.jar
错误2.9 jar包冲突
首先要说明Maven的依赖管理,具体的可以参考这边 Maven学习——依赖管理 这篇文章,maven在依赖冲管理中有一下几个原则。

    依赖是使用Maven坐标来定位的,而Maven坐标主要由GAV(groupId, artifactId, version)构成。如果两个相同的依赖包,如果groupId, artifactId, version不同,那么maven也认为这两个是不同的。
    依赖会传递,A依赖了B,B依赖了C,那么A的依赖中就会出现B和C。
    Maven对同一个groupId, artifactId的冲突仲裁,不是以version越大越保留,而是依赖路径越短越优先,然后进行保留。
    依赖的scope会影响依赖的影响范围。

当出现了依赖的时候如何快速定位冲突原因但出现了冲突的时候,比如系统出现了NoSuchMethodError,LinkageError 很有可能是你系统中出现了依赖冲突。出现冲突以后,可以按以下的步骤执行

1.确定出了问题的jar包名称。通常可以在eclipse中查找冲突的类有在哪些依赖包里面出现了。并确定实际要使用的是那个包,冲突的包有哪些。

2.通过mvn dependency:tree  >  tree.txt 导出全部的依赖。

3.在导出的依赖文件中,查找问题相关的jar。确定这些jar是如何被依赖进来的,是直接依赖的还是通过传递依赖引入的。

4. 找到相互冲突的并需要排除的依赖的顶级依赖,并分析冲突的原因,冲突的原因可能是以下几种:

    同一个jar包但groupId, artifactId不同,这种冲突只能通过设定依赖的<exclusions> 来进行排除
    需要的版本jar包依赖路径较长,这种冲突可以把想要版本的依赖直接什么在依赖中,这样路径就最短了优先级最高。

5.最后可以通过打包mvn install 来确认打出来的war包中是否有被排除的依赖。
错误2.10
Maven项目导入eclipse中很多时候都出现报错的情况,出错的原因大致可以分为下列几种:

    JDK版本不一致
    网络问题无法下载,可以尝试开vpn下载
    私有jar包

maven仓库中的某个构件如果因为网络或者其他的原因,没有下载成功或者下载被中断,将会出现一个LastUpdated的文件,这个时候,就算网络好了,也不能正常使用这个构件。
在linux系统上可以切换到仓库的目录下执行:

    find ./  -name "*.lastUpdated" -exec grep -q "Could not transfer" {} \; -print -exec rm {} \;  

执行上面的命令后删掉本地仓库的.lastupdate文件,重新构建,必要的情况可以开vpn下载。
某些一直报错的jar包,校验MD5,不对的请删掉重新构建;

错误2.11

一、无论maven还是eclipse打包都有如下的错误(错误在最后面):

二、其中错误的原因——大致是spring.xml文件中中文有编码错误,导致后面的文件无法编辑下去,致使整个项目起不来;

三、解决方法:
在eclipse中已经设置了utf-8的编码格式,但依然出现这个警告,后来查阅资料,在pom.xml文件中添加上述语句,问题解决:
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
四、从同事那里get到的一点小技能整理备用——就是排除错误的思路:

①、先到具体工作空间位置上:E:\workspace\back_wifihotel_table_workspace\back_wifihotel

②、按住shift键,再点击鼠标右键选择"在此处发开命令窗口";——这是一种快捷的方式
③、之后就可以输入mvn clean 、mvn package等命令了
问题1:

-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.

解决1:

    可以设一个windows os's环境变量M2_HOME指向你的maven安装目录    
    M2_HOME=D:\Apps\apache-maven-3.3.1    
    然后在Window->Preference->Java->Installed JREs->Edit    
    在Default VM arguments中设置    
    -Dmaven.multiModuleProjectDirectory=$M2_HOME    


问题2:
java.lang.ClassNotFoundException: org.springframework.web.util.IntrospectorCleanupListener /org.springframework.web.context.ContextLoaderListener
解决2:

    选中项目->右键Properties->选择Deployment Assemby->选择Add->选中Java Build Path Entries->Next->选择Maven Dependencies->Finish->Apply->OK    

问题3:
The import com.tsxs.common.tool.ValidateCodeImg cannot be resolved
解决3:

    Eclipse -> Project -> Clean...    
    Ok.    

问题4:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'shiroDBRealm' is defined
解决4:

    <property name="realm" ref="shiroDBRealm" />    
    <bean id="shiroDbRealm" class="com.tsxs.security.ShiroDbRealmUser"></bean>    
    配置id和ref的大小写不一致(ctrl+f搜索不区分大小写一致).字母B/b.    

问题5:
java project 转换exchange maven project:
[ERROR] Plugin org.apache.maven.plugins:maven-jar-plugin:2.4 or one of its dependencies could not be resolved: Failure to find org.apache.maven.plugins:maven-jar-plugin:jar:2.4 in http://localhost:8081/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced -> [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/PluginResolutionException
解决5:

    在Convert to Maven Project的时候修改pom.xml下:<version>0.0.1-SNAPSHOT</version>到<version>0.0.1</version>后maven clean install.    

问题6:
九月 13, 2015 1:20:48 上午 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file
[D:\developer\softwares\servers\apache-tomcat-8.0.24\webapps\weloveshare\WEB-INF\classes\applicationContext-mybatis.xml];
nested exception is com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 3 无效。
Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 3 无效。
error文件
解决6:

    最终解决:    
    1使用软件"010 Editor是一个全新的十六进位文件编辑器"查看文件头有乱码,删除保存就ok了.    
    2由于,我,重新整理的分区(双系统),无奈下,我重新搭建了一个项目,复制代码过去就ok了.    

问题7:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4或Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin: 2.4..
解决7:

    解决:重启一下console-nexus.bat就好了,或删除本地maven仓库对应的包(涉及到的根包一起删)    

问题8:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/ModelParseException
解决8:

    dependency没有在dependencies里面    

问题9:
maven中加入新的:dependency在install的时候,报错nexus没有相应的jar包
解决9:

    主要删除本地maven的repositories下的相应位置jar的路径,重新install就ok.    
    或者重启nexus或没有启动nexus。    

问题10:
Java Project转maven project因为出错没有Maven Dependencies路径
解决10:

    工程右键:Maven->Disable Maven Nature    
    然后,再次重新转maven:    
    Configure->Convert to Maven Project. ok!    

注:一般不用重启nexus服务器,除非由于进程端口占用或者服务停止,或者服务器关机或者死机,删除本地相对应的路径文件,clean install 则解决!
问题11:
设置pom.xml后,clean install编译不报错,就是不能加载Maven Dependencies和下载jar包
解决11:

    因为<dependency>在<dependencies>中,但<dependencies>又在<dependencyManagement>中,删除最外层的<dependencyManagement>后,clean install 则解决!区别解释,备注附件!    

问题12:
如果pom.xml中<dependency>标签报错画红线并报红叉,错误:Missing artifact mycoding.kaka:kaka:jar:0.0.1
在Markers中报错:
Description Resource Path Location Type
Missing artifact mycoding.kaka:kaka:jar:0.0.1 pom.xml /zJavaDemo line 20 Maven Dependency Problem
此问题解决,也适合第三方无依赖jar和本地扩展类加入maven统一管理
解决12:

    1:如果为其他技术支持网站提供的的正确的依赖<dependency>,则删除本地maven的repositories下的相应位置jar的路径和所有文件,再clean install 则解决!  
    2:Maven自定义上传第三方包到3rd party(第三方无依赖jar和本地扩展类加入maven统一管理)  

Maven自定义上传第三方包到3rd party(第三方无依赖jar和本地扩展类加入maven统一管理)
问题13:
Description Resource Path Location Type
Project configuration is not up-to-date with pom.xml. Run Maven->Update Project or use Quick Fix. webproject line 1 Maven Configuration Problem
 
解决13:

    项目上右键 ——> Maven ——> Update Project ……,打开一个(Update Maven Dependencies)的对话框,然后勾选住出错的项目,点击Ok    

问题14:
Description Resource Path Location Type
Java compiler level does not match the version of the installed Java project facet. webproject Unknown Faceted Project Problem (Java Version Mismatch)
 解决14:

    workspace下本项目的.setting下org.eclipse.jdt.core.prefs文件(修改和jdk一致版本):    
    eclipse.preferences.version=1    
    org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled    
    org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8    
    org.eclipse.jdt.core.compiler.compliance=1.8    
    org.eclipse.jdt.core.compiler.problem.assertIdentifier=error    
    org.eclipse.jdt.core.compiler.problem.enumIdentifier=error    
    org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning    
    org.eclipse.jdt.core.compiler.source=1.8    

问题15:
[ERROR] D:\DeveloperX\Code\Java\src\main\java\com\tsxs\module\utils\NetworkUtil.java:[3,25] 错误: 程序包javax.servlet.http不存在
[ERROR] D:\DeveloperX\Code\Java\src\main\java\com\tsxs\module\utils\NetworkUtil.java:[14,41] 错误: 找不到符号
解决15:

    项目右键 --> properties --> Java Build Path的libraries保证只有:JRE System Library[jdk1.8.0.66]和 Maven Dependencies     
    注:如果还有Apache Tomcat v8.0[Apache Tomcat v8.0]则,Remove删除它,在pom.xml中添加以下依赖让maven统一管理!    
    注:版本看自己jdk和tomcat版本    
        <!-- servlet/jsp -->    
        <dependency>    
            <groupId>javax.servlet</groupId>    
            <artifactId>javax.servlet-api</artifactId>    
            <version>3.1.0</version>    
        </dependency>    
        <dependency>    
            <groupId>javax.servlet.jsp</groupId>    
            <artifactId>jsp-api</artifactId>    
            <version>2.2</version>    
        </dependency>   

问题16:

    扩展:页面无controller处理跳转也需要15解决

 <!-- 容器默认的DefaultServletHandler处理 所有静态内容与无RequestMapping处理的URL -->
 <mvc:default-servlet-handler />
 <!-- 定义无需Controller的url<->view直接映射 -->
 <mvc:view-controller path="/" view-name="redirect:/index.html" />
 问题17:
Description Resource Path Location Type
One or more constraints have not been satisfied. webproject line 1 Maven Java EE Configuration Problem

提示17:

查看项目的jdk和compiler和eclipse工作空间workspace下项目下的个各个文件中版本号

 备注附件(解释学习自网络资料,非常感谢作者):

    dependencyManagement:    
    Maven 使用dependencyManagement 元素来提供了一种管理依赖版本号的方式。通常会在一个组织或者项目的最顶层的父POM 中看到dependencyManagement 元素。使用pom.xml 中的dependencyManagement 元素能让所有在子项目中引用一个依赖而不用显式的列出版本号。Maven 会沿着父子层次向上走,直到找到一个拥有dependencyManagement 元素的项目,然后它就会使用在这个dependencyManagement 元素中指定的版本号。    
    如果有多个子项目都引用同一样依赖,则可以避免在每个使用的子项目里都声明一个版本号,这样当想升级或切换到另一个版本时,只需要在顶层父容器里更新,而不需要一个一个子项目的修改 ;另外如果某个子项目需要另外的一个版本,只需要声明version就可。    
    dependencyManagement里只是声明依赖,并不实现引入,因此子项目需要显式的声明需要用的依赖。    
    dependencies:    
    相对于dependencyManagement,所有声明在dependencies里的依赖都会自动引入,并默认被所有的子项目继承。如果你要发布同样的代码,但是由于技术原因需要生成两个单独的构件,你就要使用一个分类器(classifier)。    
    classifier:    
    如果你要发布同样的代码,但是由于技术原因需要生成两个单独的构件,你就要使用一个分类器(classifier)。    
    例如,如果你想要构建两个单独的构件成JAR,一个使用Java 1.4 编译器,另一个使用Java 6 编译器,你就可以使用分类器来生成两个单独的JAR构件,它们有同样的groupId:artifactId:version组合。    
    如果你的项目使用本地扩展类库,你可以使用分类器为每一个目标平台生成一个构件。分类器常用于打包构件的源码,JavaDoc 或者二进制集合。  

问题18:
only whitespace content allowed before start tag and not \u0 (position: START_DOCUMENT se……
解决18:

    删除本地库中所有文件,重新clean install.  

错误19:

web.xml is missing and <failOnMissingWebXml> is set to true

解决19:

这时候需要右击项目——>Java EE Tools——>Generate Deployment Descriptor Stub.然后系统会在src/main/webapp/WEB_INF文件加下创建web.xml文件。错误解决!

如果你的工程不是web项目,那么还有另外一种解决方案,就是在pom文件中配置一下failOnMissingWebXml。具体配置如下: