轉】Maven實戰(三)---外掛程式動態封裝

來源:互聯網
上載者:User

標籤: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實戰(三)---外掛程式動態封裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.