结合网络大神提供的异常错误,及加上自身开发中时常遇到的一些问题,汇总到博客中,如有问题,谢谢提议;
Maven使用常见问题整理
1、更新eclipse的classpath加入新依赖
1、在dependencyManagement里面加入包括版本在内的依赖信息,如:
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>1.6.2</version>
</dependency>
2、在同级的dependencies节点里面加入该依赖,如:
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
3、使用mvn eclipse:clean删除当前的工程配置文件,并用mvn eclipse:eclipse重新生成。
4、导入或刷新该eclipse工程。
2、工程配置未使用pom.xml更新
问题:Project configuration is not up-to-date with pom.xml
导入maven工程后,出现如下错误:
Description Resource Path Location Type
Project configuration is not up-to-date with pom.xml. Run project configuration update
rdc line 1 Maven Configuration Problem
解决办法就是:
右键项目,【Maven】--》【Update Project Configuration...】即可。。。
3、如何修改默认GBK的资源过滤
Using platform encoding (GBK actually) to copy filtered resources
需要指定字符集:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
4、不支持范型的JDK版本问题
maven打包时始终出现TripApplyAction.java:[267,6]-source 1.3中不支持泛型(请使用-source 5或更高版本以启用泛型)Map<String, Object> map = new HashMap<String, Object>();
解决方法,指定JDK版本:
在pom.xml文件中加入下一面一段语句来指定所用的版本,尽管在eclipse中配置了正确的“Build Path”:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>1.5</target>
<source>1.5</source>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
重新运行mvn clean eclipse:eclipse -Dmaven.test.skip=true,接着mvn package,问题解决。
5、如何在使用命令方式下载依赖的同时下载源码
1. 使用maven命令:mvn dependency:sources 下载依赖包的源代码。
2. 使用参数: -DdownloadSources=true 下载源代码jar。 -DdownloadJavadocs=true 下载javadoc包。
7、maven打包,忽略test的参数
mvn -Dmaven.test.failure.ignore=true package
mvn -Dmaven.test.skip=true clean package
8、web.xml which will be ignored
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored
(webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')
在使用Maven 编译项目的时候会出现
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored
解决方法:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<!-- http://maven.apache.org/plugins/maven-war-plugin/ -->
<packagingExcludes>WEB-INF/web.xml</packagingExcludes>
</configuration>
</plugin>
9、Maven3.04暂时不支持Servlet3的无web.xml形式
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project prospringmvc01: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) ->
10.maven 项目站点生成时错误集锦
1 org.apache.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 18
2 changeLog 日志配置使用必需先配好scm信息
>> 版本控制报告:ChangeLog
maven-changelog-plugin能够基于版本控制系统中就近的变更记录生成三分变更报告:
* Change Log:基于提交的变更报告,包括每次提交的日期、文件、作者、注释等
* Developer Activity:基于作者的变更报告,包括作者列表以及每个作者相关的提交次数和涉及文件数目。
* File Activity:基于文件的变更报告,包括变更的文件列表以及每个文件的变更次数。
要想使用ChangeLog插件,必须先定义好SCM信息:
Xml代码 收藏代码
<scm>
<connection>scm:svn:http://192.168.1.103/app/trunk</connection>
<developerConnection>scm:svn:https://192.168.1.103/app/trunk</developerConnection>
<url>http://192.168.1.103/account/trunk</url>
</scm>
有了scm信息,开始配置maven-changelog-plugin了:
Xml代码 收藏代码
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changelog-plugin</artifactId>
<version>2.2</version>
<configuration>
<type>range</type>
<range>60</range>
</configuration>
</plugin>
11.个人使用插件环境配置问题
1. Could not resolve dependencies for project
Failed to execute goal on project user-dao: Could not resolve dependencies for project org.konghao.user:user-dao:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at org.konghao.user:user-log:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for org.konghao.user:user-log:jar:0.0.1-SNAPSHOT: Could not find artifact org.konghao.user:user-parent:pom:0.0.1-SNAPSHOT in Nexus2 (http://192.168.18.246:8089/nexus/content/groups/public) -> [Help 1]
[ERROR]
maven中maven dependencies中依赖出现了项目,把依赖的项目关掉,项目消失,但是还是无法打包 ,出现的错误如图。说明:依赖的项目为project-dao 打包的项目为project-service 都在project-parent中有依赖。project-dao是可以打包成功的。project-service中依赖dao的jar包也可以过来。
参考: http://www.oschina.net/question/143808_156035
2. 将本地jar放入到maven私服中
<dependency>
<groupId>javabuilder</groupId>
<artifactId>javabuilder</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/javabuilder.jar</systemPath>
</dependency>
3. 解决Maven关于本地jar包的打包处理
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>project-demo\lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
4. javax/servlet/ServletException 类格式异常
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2625)
at java.lang.Class.getDeclaredMethods(Class.java:1868)
解决方法: 注释
<!-- j2ee web-6.0 -->
<!-- <dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
</dependency> -->
5. JSP页面加载报错not native or abstract in class file javax/el/ValueExpression
[WARNING] EXCEPTION
javax.servlet.ServletException: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/el/ValueExpression
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:939)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:871)
at org.apache.jsp._404_jsp._jspService(org.apache.jsp._404_jsp:116)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380)
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/el/ValueExpression
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
5. No Transaction manager found 启动停顿
参考网址: http://blog.csdn.net/chaijunkun/article/details/37923905
6. could not write file: 无法再使用用户映射区域打开文件
jetty启动时,配置,解除资源文件锁定
7. Maven 项目工程延迟问题
1.debug模式进入提示参数已是Long类型
Id 类型为: int(11)
Sql 语句 : SELECT id,cname,flag,layout_type,icon,remark,nlevel,left_id,right_id
FROM `tb_article_classify`
WHERE id='1'
8. A cycle was detected in the build path of project
解决Eclipse中Java工程间循环引用而报错的问题 (慎用)
如果我们的项目包含多个工程(project),而它们之间又是循环引用的关系,那么Eclipse在编译时会抛出如下一个错误信息:
“A cycle was detected in the build path of project: XXX”
解决方法非常简单:
Eclipse Menu -> Window -> Preferences... -> Java -> Compiler -> Building -> Building path problems -> Circular dependencies -> 将Error改成Warning
9.Please ensure you are using JDK 1.4 or above and
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project clothing: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR] C:\Program Files\Java\jre6\..\lib\tools.jar
[ERROR] Please ensure you are using JDK 1.4 or above and
[ERROR] not a JRE (the com.sun.tools.javac.Main class is required).
[ERROR] In most cases you can change the location of your Java
[ERROR] installation by setting the JAVA_HOME environment variable.
[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
修改jre版本: jare改成jdk