Maven实战(三)---插件动态打包

maven把项目的构建划分为不同的生命周期(lifecycle),这个过程包括:编译、测试、打包、集成测试、验证、部署。maven中所有的执行动作(goal)都需要指明自己在这个过程中的执行位置,然后maven执行的时候,就依照过程的发展依次调用这些goal进行各种处理。

 

        下面说一下在打包的时候遇到的问题:

            Maven在用插件动态打war包的时候出现这样的错误:

[java]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  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文件:

[java]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  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生命周期的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值