From:http://depravedangel.iteye.com/blog/1450964javascript
先考慮以下實際狀況:java
純MAVEN環境比較簡單,通過一段曲折(先是修改maven-war-plguin源碼,再是自定義一個插件),最後發現竟然有一個現成的插件能夠實現這個功能,示範以下:web
<dependency>
<groupId>com.isoftstone.gads</groupId>
<artifactId>common-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.isoftstone.gads</groupId>
<artifactId>common-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>warpath</type>
</dependency>sql
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-beta-1</version>
<configuration>
<!- 必須指定,不然默認會變成在target/war/work 致使被打包進war文件,指定後爲target/work ->
<workDirectory>${project.build.directory}/work</workDirectory>
<webappDirectory>WebContent</webappDirectory>
<useCache>false</useCache>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
</archive>
<overlays>
<overlay>
<groupId>com.isoftstone.gads</groupId>
<artifactId>ebiz-common-web</artifactId>
</overlay>
<overlay>
<!-- empty groupId/artifactId is detected as the current build -->
<!-- 表明當前WAR項目,默認狀況下當前WAR項目是先被拷貝的,若是要控制其順序,則使用空的overlay -->
<!-- any other overlay will be applied after the current build since they have not been configured in the overlays
element -->
</overlay>
</overlays>
<dependentWarExcludes>*/web.xml,WEB-INF/lib/*,/sql-map-config.xml,/jdbc.properties,/META-INF/*</dependentWarExcludes>
</configuration>
</plugin>apache
<plugin>
<groupId>org.appfuse.plugins</groupId>
<artifactId>maven-warpath-plugin</artifactId>
<version>2.1.0-M1</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>add-classes</goal>
</goals>
</execution>
</executions>
<configuration><!-- below WEB-INF/classes -->
<warpathExcludes>**/logback-test.xml</warpathExcludes>
</configuration>
</plugin>app
注意紅色部分,說明以下:eclipse
純MAVEN確實很happy,可是咱們開發項目但是要在eclipse中進行的,安裝了M2E插件後 ,如何利用eclipse的WTP提供的SERVER功能進行快速的部署調式,是個須要解決的問題.webapp
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-websources-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>webSources</goal>
</goals>
</execution>
</executions>
</plugin>jsp
這個插件綁定了@phase process-resources,因此在src/main/webapp下的文件有變化時,會自動被調用,將src/main/webapp下有變化的文件拷貝到WebContent目錄下.這時就會被eclipse發現這個變化,從而同步到TOMCAT上.maven