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

原博文出于:http://blog.csdn.net/liutengteng130/article/details/41622013    感谢!

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

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

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

[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]
[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] 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文件:

<build>
<finalName>gx</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version>
<configuration>
<!--指定web.xml文件的位置,这是一种方式-->
<webXml>WebContentWEB-INFweb.xml</webXml>
<!--指定目录位置,这是另一种方式,可以把本目录下所有的xml文件都打到Jar包中-->
<!--<webResources>
            <resource>
                <directory>webContent</directory>
            </resource>
    </webResources>-->
</configuration>
</plugin>
</plugins>
</build>

  这些东西都是我们构建Maven项目必不可少的,这部分主要用到的是Maven插件机制,Maven的插件机制是依赖于Maven生命周期的。

原文地址:https://www.cnblogs.com/zlslch/p/6033629.html