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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章