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:
意思是說構建項目的時候沒有找到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生命週期的。