標籤:switch mat main 生命週期 src 部分 director play debug
原博文出於: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>WebContent\WEB-INF\web.xml</webXml>
<!--指定目錄位置,這是另一種方式,可以把本目錄下所有的xml檔案都打到Jar包中-->
<!--<webResources>
<resource>
<directory>webContent</directory>
</resource>
</webResources>-->
</configuration>
</plugin>
</plugins>
</build>
這些東西都是我們構建Maven項目必不可少的,這部分主要用到的是Maven外掛程式機制,Maven的外掛程式機制是依賴於Maven生命週期的。
轉】Maven實戰(三)---外掛程式動態封裝