maven使用中的常見異常問題整理

結合網絡大神提供的異常錯誤,及加上自身開發中時常遇到的一些問題,彙總到博客中,若有問題,謝謝提議;java

Maven使用常見問題整理

 

一、更新eclipse的classpath加入新依賴

 

一、在dependencyManagement裏面加入包括版本在內的依賴信息,如:web

              <dependency>spring

                     <groupId>joda-time</groupId>apache

                     <artifactId>joda-time</artifactId>api

                     <version>1.6.2</version>網絡

              </dependency>mvc

 

二、在同級的dependencies節點裏面加入該依賴,如:app

              <dependency>eclipse

                     <groupId>joda-time</groupId>webapp

                     <artifactId>joda-time</artifactId>

              </dependency>

 

三、使用mvn eclipse:clean刪除當前的工程配置文件,並用mvn eclipse:eclipse從新生成。

 

四、導入或刷新該eclipse工程。

 

二、工程配置未使用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...】便可。。。

 

三、如何修改默認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>

 

 

四、不支持範型的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,問題解決。

 

五、如何在使用命令方式下載依賴的同時下載源碼

 

1. 使用maven命令:mvn dependency:sources 下載依賴包的源代碼。

 

2. 使用參數: -DdownloadSources=true 下載源代碼jar。 -DdownloadJavadocs=true 下載javadoc包。

 

 

七、maven打包,忽略test的參數

 

mvn -Dmaven.test.failure.ignore=true package

mvn -Dmaven.test.skip=true clean package

 

 

八、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>

 

九、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

相關文章
相關標籤/搜索