Maven實戰(三)---插件動態打包

maven把項目的構建劃分爲不同的生命週期(lifecycle),這個過程包括:編譯、測試、打包、集成測試、驗證、部署。maven中所有的執行動作(goal)都需要指明自己在這個過程中的執行位置,然後maven執行的時候,就依照過程的發展依次調用這些goal進行各種處理。

 

        下面說一下在打包的時候遇到的問題:

            Maven在用插件動態打war包的時候出現這樣的錯誤:

  1. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.5:war (default-war) on project MavenProj1: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]  
  2. [ERROR]   
  3. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.  
  4. [ERROR] Re-run Maven using the -X switch to enable full debug logging.  
  5. [ERROR]    
  6. [ERROR] For more information about the errors and possible solutions, please read the following articles:  
  7. [ERROR] [Help 1] https://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException  

            意思是說構建項目的時候沒有找到web.xml文件,通常我們建的Maven項目的根目錄爲webapp,現在我們改爲webContent文件夾,所以我們需要指定網站的根目錄。

目錄:

webapp            

     pom.xml           

               

   └─src            

       └─main            

           ├─resources            

           └─webapp            

                index.jsp           

                           

               └─WEB-INF            

                    web.xml


修改pom文件:

  1. <build>  
  2.     <finalName>gx</finalName>  
  3.     <plugins>  
  4.         <plugin>  
  5.             <groupId>org.apache.maven.plugins</groupId>  
  6.             <artifactId>maven-war-plugin</artifactId>  
  7.             <version>2.5</version>                      
  8.             <configuration>  
  9.                 <!--指定web.xml文件的位置,這是一種方式-->  
  10.                 <webXml>WebContent\WEB-INF\web.xml</webXml>  
  11.             <!--指定目錄位置,這是另一種方式,可以把本目錄下所有的xml文件都打到Jar包中-->  
  12.               <!--<webResources>  
  13.                     <resource>  
  14.                         <directory>webContent</directory>  
  15.                      </resource>  
  16.              </webResources>-->  
  17.             </configuration>  
  18.         </plugin>  
  19.     </plugins>  
  20. </build>  

           這些東西都是我們構建Maven項目必不可少的,這部分主要用到的是Maven插件機制,Maven的插件機制是依賴於Maven生命週期的。
發佈了6 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章